演示java中Map容器的常用功能:

mport java.util.*;
     
         .............
        Map  person_message = new HashMap();
        person_message.put("sid","123");
        person_message.put("sname","lt");
        person_message.put("sphone","345");  
      
        //提取get(key)
           System.out.println(person_message.get("sphone"));        //  输出"345"
       //构建map集合中所有key对象的集合
           Set set = person_message.keySet();
           Iterator it = set.iterator();
           while(it.hasNext())
              System.out.print(it.next()+" ");                                         //  输出"sid  sname  sphone"
       //构建map集合中所有values值的集合
           Collection coll = person_message.values();
            Iterator it = coll.iterator();
            while(it.hasNext())
                System.out.print(it.next()+" ");                                    //  输出"123 lt  345"

你可能感兴趣的:(java)