码迷,mamicode.com
首页 > 编程语言 > 详细

Java中Map集合遍历

时间:2015-02-06 14:33:31      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:

public static void main(String[] args) {


HashMap<String,String> map = new HashMap<String,String>();

map.put("张三", "四川");
map.put("李四", "四川");
map.put("王五", "广东");
map.put("赵六", "北京市");
map.put("钱七", "河北省");


System.out.println(map);

Set<String> set = map.keySet();

for (Iterator<String> it = set.iterator(); it.hasNext();) {

String str = it.next();
System.out.print(str+"==="+map.get(str));
}

System.out.println();

for (String str : set) {
System.out.print(str+"来自"+map.get(str)+",");
}


System.out.println();
Set<Entry<String,String>> entrySet = map.entrySet();

Iterator<Entry<String,String>> entry = entrySet.iterator();
while(entry.hasNext()){
Entry<String,String> en = entry.next();
System.out.print(en.getKey() + "--" + en.getValue());
}
}

Java中Map集合遍历

标签:

原文地址:http://www.cnblogs.com/ghostqf/p/4276991.html

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