Does serial stream in Java 8 have a combiner parameter when calling collect?

If I call collection in a serial stream (for example, from a call to Collection.stream ()), will it use the combiner parameter that I pass for collection? I suppose but don't see anything in the documentation. If I am right, then, unfortunately, I will have to supply what I know will not be used (if I know that this is a sequential stream).

+18
java java-8 java-stream
Jun 13 '14 at 9:49
source share
1 answer

Keep in mind that you are developing interface specifications - not against implementation. Implementation may change with the next version of Java, while the specification should remain stable.

There are no differences between serial and parallel streams in the specification. For this reason, you should assume that combiner can be used. There are actually good examples showing that combinators for serial threads can improve performance. For example, the following shrink operation combines a list of strings. Executing code without a combiner has quadratic complexity. Reasonable execution with a combiner can reduce the execution time in magnitude.

List<String> tokens = ...; String result = tokens.stream().reduce("", String::concat, String::concat); 
+17
Jun 13 '14 at 14:12
source share



All Articles