首页 > 其他 > 详细

HashMap的遍历

时间:2014-03-03 19:41:19      阅读:517      评论:0      收藏:0      [点我收藏+]


Map<String,String> mapList=new HashMap<String, String>();
mapList.put("AA", "测试");
mapList.put("BB", "我在");
//方式1 比较建议方式一的做法
Iterator iterator = mapList.keySet().iterator();
while(iterator.hasNext()) {
System.out.println(mapList.get(iterator.next()));
System.out.println(mapList.get(iterator.next()));
}

//方式2
// java.util.Iterator it = mapList.entrySet().iterator();
// while(it.hasNext()){
// java.util.Map.Entry entry = (java.util.Map.Entry)it.next();
//// entry.getKey() 返回与此项对应的键
//// entry.getValue() 返回与此项对应的值
// System.out.println(entry.getValue());
// System.out.println(entry.getKey());
// }

HashMap的遍历,布布扣,bubuko.com

HashMap的遍历

原文:http://www.cnblogs.com/shuenjian901/p/3577918.html

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