Parallel-Streams
Parallel-Streams
并行流。stream
流是支持顺序和并行的。顺序流操作是单线程操作,串行化的流无法带来性能上的提升,通常我们会使用多线程来并行执行任务,处理速度更快。
/**
* @description:
* @author: 程序员大彬
* @time: 2021-09-06 00:05
*/
public class StreamTest7 {
public static void main(String[] args) {
int max = 100;
List<String> strs = new ArrayList<>(max);
for (int i = 0; i < max; i++) {
UUID uuid = UUID.randomUUID();
strs.add(uuid.toString());
}
List<String> sortedStrs = strs.stream().sorted().collect(Collectors.toList());
System.out.println(sortedStrs);
}
/**
* output
* [029be6d0-e77e-4188-b511-f1571cdbf299, 02d97425-b696-483a-80c6-e2ef51c05d83, 0632f1e9-e749-4bce-8bac-1cf6c9e93afa, ...]
*/
}
Loading...