1List<String> items = new ArrayList<>();
2items.add("A");
3items.add("B");
4items.add("C");
5items.add("D");
6items.add("E");
7
8//lambda
9//Output : A,B,C,D,E
10items.forEach(item->System.out.println(item));
11
12//Output : C
13items.forEach(item->{
14 if("C".equals(item)){
15 System.out.println(item);
16 }
17});
18
19//method reference
20//Output : A,B,C,D,E
21items.forEach(System.out::println);
22
23//Stream and filter
24//Output : B
25items.stream()
26 .filter(s->s.contains("B"))
27 .forEach(System.out::println);
1Set<String> set = new HashSet<String>();
2
3//populate set
4
5for (String s : set) {
6 System.out.println(s);
7}
8