IntStream 与通常的 Stream 相比有什么优势?

What is the advantage of IntStream over usual Stream?(IntStream 与通常的 Stream 相比有什么优势?)
本文介绍了IntStream 与通常的 Stream 相比有什么优势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IntStreamDoubleStreamLongStream 如何优于 Java 8 中的常规流?

How is IntStream, DoubleStream, or LongStream better than regular stream in Java 8?

这些线程是否具有高性能或可用性?

Do these threads have high performance or maybe usability?

推荐答案

Stream<Integer> 等必须使用装箱值(Integer 而不是原始 int) 会占用更多内存,并且通常需要大量装箱/拆箱操作(取决于您的代码).为什么只有 Int/Double/Long?只是因为它们被期望最常使用.

Stream<Integer> etc. have to work with boxed values (Integer instead of primitive int) which takes significantly more memory and usually a lot of boxing/unboxing operations (depending on your code). Why only Int/Double/Long? Just because they were expected to be used most often.

同样适用于 OptionalInt 和朋友以及所有功能接口.

Same applies to OptionalInt and friends and all the functional interfaces.

对于集合(列表/地图/集合),出于同样的原因,有许多第三方库提供原始专业化.确实,问题更加严重,因为对于流,您不需要(通常;sorted() 是一个反例)需要在内存中存储许多值.

For collections (lists/maps/sets) there are many third-party libraries providing primitive specialization for the same reason. Really the problem there is even more acute because with streams you don't (usually; sorted() is a counter-example) need to store many values in memory.

这篇关于IntStream 与通常的 Stream 相比有什么优势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How can create a producer using Spring Cloud Kafka Stream 3.1(如何使用Spring Cloud Kafka Stream 3.1创建制片人)
Insert a position in a linked list Java(在链接列表中插入位置Java)
Did I write this constructor properly?(我是否正确地编写了这个构造函数?)
Head value set to null but tail value still gets displayed(Head值设置为空,但仍显示Tail值)
printing nodes from a singly-linked list(打印单链接列表中的节点)
Control namespace prefixes in web services?(控制Web服务中的命名空间前缀?)