jdk1.8新特性

遍历map
Map<string,object> map = new HashMap<>();
map.put("name","张三");
map.put("age","28");
map.put("siteId","100000");

jdk1.8之前
// 增强for循环
for(mapEntry(String,Object) entry:map.entrySet()){
System.out.println(entry.getKey()+":"+ entry.getValue());
}

jdk1.8
// foreach
map.forEach((key,value) ->
System.out.println(key+":"+value);
)

 

posted @ 2021-10-12 10:10  Only_Aptx-4869  阅读(40)  评论(0)    收藏  举报