1 package jihe; 2 import java.util.*; 3 public class TestMap { 4 5 public static void main(String[] args) { 6 // 创建Map集合,创建Emp对象,并将创建的Emp对象添加到集合中(Emp对象的id作为Map集合的键), 7 //并将id为005的对象从集合中删除 8 Map<String,String> Emp=new HashMap<>(); 9 Emp.put("001","宜"); 10 Emp.put("002","兒"); 11 Emp.put("003","䀐"); 12 Emp.put("004","兕"); 13 Emp.put("005","䉑"); 14 Emp.remove("005"); 15 System.out.println(" "+Emp.get("001")); 16 Set<String> s=Emp.keySet(); 17 for(String ss:s) 18 { 19 System.out.println(ss+"="+Emp.get(ss)); 20 } 21 System.out.println(" Iterator遍历"); 22 Iterator<String> it=s.iterator(); 23 while(it.hasNext()) 24 { 25 String ss=it.next(); 26 System.out.println(ss+"="+Emp.get(ss)); 27 } 28 29 30 } 31 32 }