简体   繁体   中英

Does Stream.boxed() preserve order?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM