日出之美便在于它脱胎于最深的黑暗。——辛夷坞
代码:
1 2 3 4
| System.out.println(Stream.concat(Stream.of(1), Stream.of(1)).isParallel()); System.out.println(Stream.concat(Stream.of(1).parallel(), Stream.of(1)).isParallel()); System.out.println(Stream.concat(Stream.of(1), Stream.of(1).parallel()).isParallel()); System.out.println(Stream.concat(Stream.of(1).parallel(), Stream.of(1).parallel()).isParallel());
|
结论:连接的两个流,只要其中有一个是并行流,最终的流则为并行流
顺便放一个排序的特征,说明Spliterator
特征不受合并影响
1 2 3 4 5
| System.out.println(Stream.concat(Stream.of(1, 2).sorted(), Stream.of(1)).spliterator().hasCharacteristics(Spliterator.SORTED)); System.out.println(Stream.concat(Stream.of(1), Stream.of(1, 2).sorted()).spliterator().hasCharacteristics(Spliterator.SORTED));
System.out.println(Stream.concat(Stream.of(1), Stream.of(1, 2).distinct()).spliterator().hasCharacteristics(Spliterator.SORTED)); System.out.println(Stream.concat(Stream.of(1).distinct(), Stream.of(1)).spliterator().hasCharacteristics(Spliterator.SORTED));
|