首页 > 代码库 > 两种不同分HashMap扩展的方法

两种不同分HashMap扩展的方法

import java.util.*;class  hashMapDemo3{    public static void main(String[] args)     {                HashMap<String,String> groupA = new HashMap<String,String>();        groupA.put("ben","01");        groupA.put("sam","02");        groupA.put("edison","03");        groupA.put("nancy","04");                HashMap<String,String> groupB = new HashMap<String,String>();        groupB.put("Btusom","01");        groupB.put("Bsammy","02");        groupB.put("Beson","03");        groupB.put("Bnanny","04");                HashMap<String,HashMap<String,String>> itcast = new HashMap<String,HashMap<String,String>>();        itcast.put("groupA",groupA);        itcast.put("groupB",groupB);                Iterator<String> it = itcast.keySet().iterator();        while(it.hasNext())        {            String id = it.next();            HashMap<String,String> group = itcast.get(id);            groupInfo(group);        }        //System.out.println("Hello World!");    }    public static void groupInfo(HashMap<String,String> hm)    {        Iterator<String> it = hm.keySet().iterator();        while(it.hasNext())        {            String id = it.next();            String name = hm.get(id);            System.out.println(id+" "+name);        }    }}
public static void getInfos(List<Student> list)    {        Iterator<Student> it = list.iterator();        while(it.hasNext())        {            Student s = it.next();            System.out.println(s);        }    }

 

两种不同分HashMap扩展的方法