A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 新手ing 中级黑马   /  2015-7-12 10:08  /  485 人查看  /  6 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

        //第一种方式
        Set<String> keySet = map.keySet();
        Iterator it = keySet.iterator();
        while(it.hasNext()){
                String key = (String)it.next();
                String value = map.get(key);
                System.out.println(key+"------"+value);
        }
        //第二种方式
        Set<Entry<String,String>> set = map.entrySet();
        Iterator it1 = set.iterator();
        while(it1.hasNext()){
                Entry<String,String> entry = (Entry<String,String>)it1.next();
                String key = entry.getKey();
                String value = entry.getValue();
                System.out.println(key+"------"+value);
        }
        //第三种方式
   for(Entry<String,String> entry : map.entrySet()){
                        System.out.println((String)entry.getKey() + "------"
                                        + (String)entry.getValue());
    }

6 个回复

倒序浏览
学习了,现在用增强for循环比较多
回复 使用道具 举报
刚看到这,:dizzy:思维结构有点乱了
回复 使用道具 举报
学习了.....................
回复 使用道具 举报
遍历map集合不是说两种吗,keySet和entrySet。
回复 使用道具 举报
谢谢分享!!!
回复 使用道具 举报
妳的微笑 发表于 2015-7-12 16:43
遍历map集合不是说两种吗,keySet和entrySet。

基本用增强for循环
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马