Reputation: 13137
What is the easiest way of iterating through all the entries in a Map using the new Java 8?
Upvotes: 1
Views: 225
Reputation: 13137
I believe this is the most concise and easiest way to iterate through all the entries in a Map:
Create map:
Map map = new HashMap() {{
put("key1", "value1");
put("key2", "value2");
}};
Go through all the keys and values:
map.forEach( (k, v) -> System.out.println("key: " + k + " value: " + v) );
Upvotes: 5