`
zhaolicric
  • 浏览: 143805 次
  • 性别: Icon_minigender_2
  • 来自: 青岛
社区版块
存档分类
最新评论

Map,HashMap的使用

 
阅读更多

 

 

Map<Integer, String> temp = new HashMap<Integer, String>();

		for (int i = 0; i < 10; i++) {
			String str = "string" + i;
			temp.put(new Integer(i), str);
		}
		if (temp.containsKey(new Integer(5))) {// 判断键是否重复
			System.out.println("Contains!");
		} else {
			System.out.println("No contains!");
		}
		for (Iterator it = temp.entrySet().iterator(); it.hasNext();) {
			Map.Entry e = (Map.Entry) it.next();
			System.out.print("key: " + e.getKey());
			System.out.println(" value: " + e.getValue());
		}
 
关于HashMap的存值和迭代.

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics