My computer has 4 cores and now I ran the stringList list on the 4 cores using the parallel method and called the reduce method with the value identity = "A". Normally, this list should be divided into 4 parts, and in each processor, the identity should be added to each part (reduced) and the result should be A12 A34, A56 A78, but the result was something else that is mentioned in the following code. Why did this happen?
List<String> stringList = new ArrayList<>();
stringList.add("1");
stringList.add("2");
stringList.add("3");
stringList.add("4");
stringList.add("5");
stringList.add("6");
stringList.add("7");
stringList.add("8");
String result = stringList.stream()
.parallel()
.reduce(" A", (s1, s2) -> s1 + s2);
System.out.println("result:" + result); //result: A1 A2 A3 A4 A5 A6 A7 A8