[英]Using Java 8, what is the most concise way of iterating through all the entries in a map?
使用新的Java 8迭代Map中所有条目的最简单方法是什么?
I believe this is the most concise and easiest way to iterate through all the entries in a Map: 我认为这是迭代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) );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.