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

Map的循环

时间:2015-10-05 23:20:31      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

import java.util.*;
import java.util.Map.Entry;
public class UseMap {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Map<Integer,String> map = new HashMap<Integer,String>();
        map.put(0,"李鹏飞");
        map.put(1, "王萌");
        map.put(2,"over");
        //使用迭代器
        Iterator<Integer> it = map.keySet().iterator();
        while(it.hasNext()) {
            Integer id = it.next();
            String name = map.get(id);
            System.out.println(id + " " + name );
        }
        //最简洁的循环
        for(Entry<Integer,String> entry : map.entrySet()) {
            System.out.println(entry.getKey() + " " + entry.getValue());
        }
    }
}

 

Map的循环

标签:

原文地址:http://www.cnblogs.com/dev-lipengfei/p/4856395.html

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