码迷,mamicode.com
首页 > 其他好文 > 详细

两种不同分HashMap扩展的方法

时间:2014-11-25 22:42:19      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:style   blog   ar   color   os   sp   java   on   div   

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扩展的方法

标签:style   blog   ar   color   os   sp   java   on   div   

原文地址:http://www.cnblogs.com/tozr/p/4121885.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!