IntStream与普通Stream相比有什么优势? [英] What is the advantage of IntStream over usual Stream?

查看:426
本文介绍了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相比有什么优势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆