首页 > 其他 > 详细

HashMap初始化以及遍历的三种方式

时间:2014-09-29 12:03:11      阅读:240      评论:0      收藏:0      [点我收藏+]

public static void main(String[] args){

Map<String, String> map = new HashMap<String, String>(){

{

put("zhang","xinxin");

put("wnag", "jinfeng");

put("li", "xuemei");

put("zhao", "xinyi");

}

};

System.out.println("NO1.===========================");

for(Entry<String, String> entry : map.entrySet())

{

System.out.println("key: " + entry.getKey() + "    value: " + entry.getValue() );

}

System.out.println("NO2.===========================");

for (String key : map.keySet()) 

{

System.out.println("key: " + key + "    value: " + map.get(key));

}

System.out.println("NO3.===========================");

Iterator<Entry<String, String>> it = map.entrySet().iterator();

while (it.hasNext()) {

Entry<String, String> en = it.next();

System.out.println("key: " + en.getKey() + "    value: " + en.getValue() );

}

}

HashMap初始化以及遍历的三种方式

原文:http://www.cnblogs.com/xinxinz/p/3999884.html

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