一、stream()、parallelStream()区别
1、数据准备
List<String> list = ListUtil.toList("2", "1", "3", "4", "5");
2、stream() 示例
list.stream().forEach(item -> {
System.out.println("stream.forEach:" + item);
});
输出:
stream.forEach:2
stream.forEach:1
stream.forEach:3
stream.forEach:4
stream.forEach:5
3、parallelStream() 示例
list.parallelStream().forEach(item -> {
System.out.println("parallelStream.forEach:" + item);