我已经通过像前几次问题了在Java流相遇为了保鲜,这个答案Brian Goetz撰写,还有的javadoc的Stream.reduce(),和java.util.stream包的javadoc,但我仍然可以” t掌握以下内容:
采取这段代码:
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));
}
Run Code Online (Sandbox Code Playgroud)
为什么减少总是*保留相遇顺序?