1.java map多个值使用相同的key
Map<Integer, Integer> map = new IdentityHashMap<>();
map.put(new Integer(1),1);
map.put(new Integer(1), 2);
map.put(new Integer(1), 3);
map.put(new Integer(2), 3);
System.out.println(map.size());
for (Integer row : map.keySet()) {
System.out.println(row+"===="+map.get(row));
}
2.遍历map的key和value
public static void main(String[] args) {
Map<Integer, Integer> map_error = new IdentityHashMap<>();
//给map_error存放值
saveMap(map_error);
Map<Integer, Integer> map = map_error;
for(Map.Entry<Integer, Integer> entry : map.entrySet()){
System.out.println("key = " + entry.getKey() + ", value = " + entry.getValue());
}
}
public static void saveMap(Map<Integer, Integer> map_e){
map_e.put(new Integer(1),1);
map_e.put(new Integer(1), 2);
map_e.put(new Integer(1), 3);
map_e.put(new Integer(2), 3);
}