用entrySet遍历Map


import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MapTest4 {
	public static void main(String[] args) {
		HashMap map = new HashMap();
		map.put("1", "a");
		map.put("2", "b");
		map.put("3", "c");
		map.put("4", "d");
		map.put("5", "e");
		map.put("6", "f");
		Set set = map.entrySet();
		Iterator iter = set.iterator();
		while(iter.hasNext()){
			Map.Entry entry = (Map.Entry)iter.next();
			String key = (String)entry.getKey();
			String value = (String)entry.getValue();
			System.out.println(key+ "=" +value);
		}
	}
}

 

你可能感兴趣的:(entrySet)