天天看點

Map疊代方式,Map疊代,Map循環

Map疊代方式,Map疊代,Map循環

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

蕃薯耀 2015年7月2日 09:19:11 星期四

http://fanshuyao.iteye.com/

public static void main(String[] args) {

		HashMap map = new HashMap();
		map.put("a", "is a.");
		map.put("b", "is b.");
		map.put("c", "is c.");
		map.put("d", "is d.");
		map.put("a", "is aaaaaaaaaaaaaaaaaaaaa.");//鍵不變,a的值改變
		
		//map疊代方式一
		Set set = map.keySet();
		for(Iterator iterator = set.iterator();iterator.hasNext();){
			String key = (String) iterator.next();
			String value = (String) map.get(key);
			System.out.println("key="+key+", value="+value);
		}
		
		System.out.println("--------------------------------------");
		
		//map疊代方式二
		Set s = map.entrySet();
		for(Iterator it = s.iterator();it.hasNext();){
			Map.Entry en = (Map.Entry) it.next();
			System.out.println("key="+en.getKey()+", value="+en.getValue());
		}
		
	}
           

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

蕃薯耀 2015年7月2日 09:19:11 星期四

http://fanshuyao.iteye.com/