一、for循环
Map<Integer,Integer> map = new HashMap<>();
map.put(1, 1);
map.put(3, 2);
for(int i : map.keySet()){
System.out.println(map.get(i));
}
二、entrySet遍历
public static void main(String[] args) {
Map<Integer,Integer> map = new HashMap<>();
map.put(1, 1);
map.put(3, 2);
for(Map.Entry<Integer,Integer> i : map.entrySet()){
System.out.println(i);
}
}
三、foreach方法遍历
public static void main(String[] args) {
Map<Integer,Integer> map = new HashMap<>();
map.put(1, 1);
map.put(3, 2);
map.forEach((key,value)-> System.out.println(key+"///"+value));
}