Stream.boxed()是否保留顺序? [英] Does Stream.boxed() preserve order?

查看:1602
本文介绍了Stream.boxed()是否保留顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个无限的流。

Assume I have an infinite Stream.

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

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()删除了排序约束。

  • sorted()更改订单。

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

如果没有明确指定,您可以假设操作保持订单。即使 distinct()也会保留订单,但它会增加并行流的复杂性。

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.

这篇关于Stream.boxed()是否保留顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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