Where is defined the combination order of the combiner of collect(supplier, accumulator, combiner)?

后端 未结 2 865
遥遥无期
遥遥无期 2020-12-17 21:36

The Java API documentations states that the combiner parameter of the collect method must be:

an associative, non-interferi

2条回答
  •  误落风尘
    2020-12-17 22:20

    Seems that this is not explicitly stated in the documentation. However there's an ordering concept in streams API. Stream can be either ordered or not. It may be unordered from the very beginning if source spliterator is unordered (for example, if the stream source is HashSet). Or the stream may become unordered if user explicitly used unordered() operation. If the stream is ordered, then collection procedure should also be stable, thus, I guess, it's assumed that for ordered streams the combiner receives the arguments in the strict order. However it's not guaranteed for an unordered stream.

提交回复
热议问题