哪些操作保留了订单 [英] Which operations preserve order

查看:94
本文介绍了哪些操作保留了订单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL; DR; 我正在寻找一个可以查找某个中间操作或终端操作的地方。我在哪里可以找到这样的文档?

TL;DR; I am looking for a place where I can lookup whether a certain intermediate or terminal operation. Where can I find such documentation?

编辑这不是如何确保java8流中的处理顺序?,因为该问题没有提供全面的操作列表。

Edit This is not a duplicate of How to ensure order of processing in java8 streams?, since that question does not provide a comprehensive list of operations.

包文档说:


流是否有遭遇订单取决于来源和中间操作

Whether or not a stream has an encounter order depends on the source and the intermediate operations

这个优秀的stackoverflow答案


为了确保在整个流操作中维护订购,你必须学习文档流的源,所有中间操作和终端操作是否维持订单(或者消息来源是否首先订购)。

In order to ensure maintenance of ordering throughout an entire stream operation, you have to study the documentation of the stream’s source, all intermediate operations and the terminal operation for whether they maintain the order or not (or whether the source has an ordering in the first place).

这是一切都很好,但我应该看哪些文件? 包文档在一个示例中提到 map 保证排序,但它没有详尽的列表。用于Stream类的 javadoc 记录一些中间操作,但不是全部。
例如 map

That is all well and good, but which documentation should I look at? The the package documentation mentions in an example that map guarantees ordering, but it doesn't have a exhaustive list. The javadoc for the Stream class documents some intermediate operations, but not all. Take for example map:


返回一个流,包含将给定函数应用于此流元素的结果。

Returns a stream consisting of the results of applying the given function to the elements of this stream.

这是一个中间操作。

过滤器


返回一个流,该流由与该给定谓词匹配的此流的元素组成。

Returns a stream consisting of the elements of this stream that match the given predicate.

这是一个中间操作。

这些都没有描述它们是否保留订购。

None of these describe whether they preserve ordering.

此stackoverflow答案声明:

实际上,每个中间操作都会默认保留订单。唯一的例外是:

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


  • unordered()删除了排序约束。

  • sorted()这改变了订单。

如果没有明确指定,你可以假设操作保持订单。即使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.

但是有任何官方文档可以支持它?

but is there any official documentation to back that up?

这篇关于哪些操作保留了订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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