11月7 记录好的方案

 

每次做项目我们或多或少都会遇到一些问题,会有收获。

一些好的方案,然后时间一久,就会遗忘,代码在哪也不知道了。

所以我决定将这些方案和代码记录下来

 

 

oreach + 拉姆达表达式

 

List<String> items = new ArrayList<>();
items.add("A");
items.add("B");
items.add("C");
items.add("D");
items.add("E");
 
//lambda
//Output : A,B,C,D,E
items.forEach(item->System.out.println(item));
 
//Output : C
items.forEach(item->{
    if("C".equals(item)){
        System.out.println(item);
    }
});
 
//method reference
//Output : A,B,C,D,E
items.forEach(System.out::println);
 
//Stream and filter
//Output : B
items.stream()
    .filter(s->s.contains("B"))
    .forEach(System.out::println);

 

posted @ 2018-11-07 15:01  lyon♪♫  阅读(84)  评论(0编辑  收藏  举报