我朋友都在用的的stream 偶然刷到帖子简单写写
public static void main(String[] args) {
List<String> names = Arrays.asList("Alice", "Bob", "Charlie","Bob", "Charlie");
List<byte[]> rec = names.stream().distinct().map(s -> s.getBytes()).collect(Collectors.toList());
System.out.println(1);
Date date = new Date();
System.out.println("并行测试时间"+date);names.stream().parallel().map(s -> {
s = s +100;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return s;
}).forEach(s ->{
s = String.valueOf(test.cc(s)) ;
System.out.println(s);});
Date date1 = new Date();
System.out.println("并行测试时间"+date1);
Date date2 = new Date();
System.out.println("非并行测试时间"+date2);
names.stream().map(s -> {
s = s +100;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return s;
}).forEach(System.out::println);
Date date3= new Date();
System.out.println("非并行测试时间"+date3);
}
public static int cc(String S){
return 1;
}