首页 > 移动平台 > 详细

android HashMap的几种遍历方法

时间:2014-07-25 16:35:21      阅读:381      评论:0      收藏:0      [点我收藏+]

HashMap的几种遍历方法

1、第一种:

   Map<String, ArrayList> map = new HashMap<String, ArrayList>();
   Set<String> keys = map.keySet();
   Iterator<String> iterator = keys.iterator();
   while (iterator.hasNext()) {
        String key = iterator.next();
        ArrayList arrayList = map.get(key);
        for (Object o : arrayList) {
            System.out.println(o + "遍历过程");
        }
    }

 

2、第二种:

    Map<String, Integer> tempMap = new HashMap<String, Integer>();
    tempMap.put("a", 1);
    tempMap.put("b", 2);
    tempMap.put("c", 3);
    for (String o : tempMap.keySet()) {
        System.out.println("key=" + o + " value=" + tempMap.get(o));
    }

 

3、第三种:

    Map<String, Integer> tempMap = new HashMap<String, Integer>();
    tempMap.put("a", 1);
    tempMap.put("b", 2);
    tempMap.put("c", 3);
    for (Iterator i = tempMap.keySet().iterator(); i.hasNext();) {
        String obj = i.next();
        System.out.println(obj);// 循环输出key
        System.out.println("key=" + obj + " value=" + tempMap.get(obj));
    }

 

 

android HashMap的几种遍历方法,布布扣,bubuko.com

android HashMap的几种遍历方法

原文:http://www.cnblogs.com/fly-allblue/p/3867852.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!