-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForEachExample.java
More file actions
44 lines (26 loc) · 941 Bytes
/
Copy pathForEachExample.java
File metadata and controls
44 lines (26 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.kml.java8.lamda;
import com.kml.java8.common.Data;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author Kemal Acar
*/
public class ForEachExample {
public static void main(String[] args) {
List<String> continents = Data.continents;
AtomicInteger i = new AtomicInteger(); // you can atomic variables in scope of lamda.
System.out.println("Continents : ");
continents.forEach((continent) -> {
System.out.println("\t"+(i.incrementAndGet()) +" = " + continent);
});
System.out.println("\nCountries : ");
Map<String, List<String>> cityCountryMap = Data.cityCountryMap;
cityCountryMap.forEach((key, value) -> {
System.out.println("\t"+ key);
value.forEach(city -> {
System.out.println("\t\t" +city);
});
});
}
}