import java.util.Collection; import java.util.HashMap; import java.util.Set; public class HasMapDemo { public static void main(String[] args) { HashMap<Integer,String> map = new HashMap<Integer,String>(); //添加元素 map.put(001, "诸葛亮"); map.put(002, "刘备"); map.put(003, "张飞"); //删除指定key值的元素 map.remove(002); //得到指定key值得value System.out.println(map.get(001)); //得到key值集 Set<Integer> set = map.keySet(); //得到value集 Collection<String> c=map.values(); //遍历map for(Integer i:map.keySet()) { System.out.println(map.get(i)); } } }