Does Stream.boxed() preserve order?

落爺英雄遲暮 提交于 2019-12-24 00:27:39

问题


Assume I have an infinite Stream.

IntStream istream = IntStream.iterate(0, i -> i + 1).limit(100);
Stream<Integer> boxedStream = istream.boxed();

Does the boxed() method preserve order? Probably yes, but I cannot find it in the documentation.


回答1:


Actually every intermediate operation preserves an order by default. The only exceptions are:

  • unordered() which removes the ordering constraint.
  • sorted() which changes the order.

When it's not explicitly specified, you can assume that operation keeps the order. Even distinct() keeps the order, though it adds much complexity for parallel stream.



来源:https://stackoverflow.com/questions/35658579/does-stream-boxed-preserve-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!