java 如何遍历Map对象

内容介绍

在java中遍历Map对象的方法。

Map对象

Map<String,Object> map = new HashMap<>();
map.put("xiaoming", 1.78);
map.put("wanghong", 1.64);
map.put("zhangcan", 1.58);

遍历

for (Map.Entry<String, Object> entity : map.entrySet()){
    System.out.println(String.format("key[%s]---->[%s]", entity.getKey(),entity.getValue()));
}

结果

原文地址:https://www.cnblogs.com/codecat/p/11159780.html