I reviewed a few previous questions, such as Preserving the Encounter order in a java stream , this answer by Brian Goetz, as well as the javadoc for Stream.reduce (), and the java.util.stream javadoc package , and yet I still can not understand following:
Take this piece of code:
public static void main(String... args) { final String[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""); System.out.println("Alphabet: ".concat(Arrays.toString(alphabet))); System.out.println(new HashSet<>(Arrays.asList(alphabet)) .parallelStream() .unordered() .peek(System.out::println) .reduce("", (a,b) -> a + b, (a,b) -> a + b)); }
Why does reduction always * keep the order of meetings?
unordered ; , , Stream, .
unordered
, , ( ).
( ) jdk-8 jdk-9 - reduce . , .
jdk-8
jdk-9
reduce
, unordered - , , , , .
, /, , findFirst ( ) , unordered java-9 java-8.
findFirst
, ABCD.
ABCD
: AB CD. , AB , , CD , . , .
AB
CD
unordered , limit, reduce.
limit
Source: https://habr.com/ru/post/1683047/More articles:Repeatedly missing Microsoft Office links in Visual Basic - referenceMatplotLib 'saveFig ()' Fullscreen - pythondifference between ndk-bundle and android-ndk-r15c - androidHow to count the number of events for a row in a cell? - vbaWhat is the new download URL for the PyPI test server? - pythonchain methods in base and derived classes - c #Saving order in java thread - javasklearn train_test_split on pandas stratify across multiple columns - pythonHigh CPU utilization with RTCPeerConnections - performanceAngular Dynamic Injection Component Error - dynamicAll Articles