package com.xiaoshangkou.MapTest;
import java.util.Map;
import java.util.Set;
public class HashMap {
public static void main(String[] args) {
Map<Integer,String>map=new java.util.HashMap<>();
Map<Integer,String>map1=new java.util.HashMap<>();
map.put(1111,"zhangsan");
map.put(6666,"lisi");
map.put(7777,"wangwu");
map.put(2222,"zhaoliu");
map.put(2222,"king");//key重复的时候value会自动覆盖
map1.putAll(map);
System.out.println(map1.size());
System.out.println(map.size());
//遍历Map集合
System.out.println("map集合");
Set<Map.Entry<Integer,String>> set=map.entrySet();
for (Map.Entry<Integer,String> entry:set){
System.out.println(entry.getKey()+"="+entry.getValue());
}
System.out.println("");
//遍历map1集合
System.out.println("map1集合:");
Set<Map.Entry<Integer,String>> set1=map1.entrySet();
for (Map.Entry<Integer,String> entry:set){
System.out.println(entry.getKey()+"="+entry.getValue());
}
}
}