public static void main(String[] args) throws IOException {
Map<String, Object> map = new HashMap<String, Object>();
map.put("key1", "value1");
map.put("key2", "value2");
map.put("key3", "value3");
map.put("key4", "value4");
map.put("key5", "value5");
// 遍历map 方法1
Set<String> keySet = map.keySet();
for (String key : keySet) {
String value = map.get(key).toString();
System.out.println(key + "==" + value);
}
System.out.println("==========================================");
// 遍历map 方法2
Iterator<String> iterator = map.keySet().iterator();
while (iterator.hasNext()) {
String key = (String) iterator.next(); //获取key
String value = map.get(key).toString(); //获取value
System.out.println(key + "==" + value);
}
}
java遍历Map集合
最新推荐文章于 2024-05-29 11:01:59 发布