Stream中的map操作

stream的map操作:对流操作,返回一个新的流。

如果map操作后,没有执行collect方法,那么就没有返回新的流,因此map中的操作也不会生效。

 1 public static void main(String[] args) {
 2 
 3         List<Integer> list1 = Arrays.asList(1, 2, 3, 4, 5, 6);
 4         list1.stream().map(a->{
 5             System.out.println("没有返回新的流"+a*10);
 6             return a;
 7         });
 8         list1.stream().map(a->{
 9             System.out.println("返回新的流"+a*10);
10             return a;
11         }).collect(Collectors.toList());
12 
13 
14     }

猜你喜欢

转载自www.cnblogs.com/wxt-nb/p/11184474.html