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);
1int [] intArray = { 10, 20, 30, 40, 50 };
2
3for( int value : intArray ) {
4 System.out.println( value );
5}
1//itemset contains variables of type <Data Type>
2for(<Data Type> item : itemset) {
3 //loop
4}
1List<String> someList = new ArrayList<String>();
2// add "monkey", "donkey", "skeleton key" to someList
3for (String item : someList) {
4 System.out.println(item);
5}