标签:
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()); } } }
标签:
原文地址:http://www.cnblogs.com/dev-lipengfei/p/4856395.html