方法如下:
public static void main(String[] args) {
//新建Map然后填入数据
Map<String, String> map = new HashMap<>();
map.put("key_one", "one");
map.put("key_two", "two");
map.put("key_three", "three");
map.put("key_four", "four");
map.put("key_five", "five");
//通过Map.Entry<>进行遍历
for (Map.Entry<String, String> entry:map.entrySet()) {
System.out.println(entry.getKey()); //获取到map 键
System.out.println(entry.getValue()); //获取到map 值
}
}