Java 8 Lambda Stream forEach with multiple statements

前端 未结 4 882
心在旅途
心在旅途 2021-02-01 12:44

I am still in the process of learning Lambda, please excuse me If I am doing something wrong

final Long tempId = 12345L;
List updatedEntries = new L         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-01 13:24

    List 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->{
        System.out.println(item);
        System.out.println(item.toLowerCase());
      }
    });
    

提交回复
热议问题