用keySet遍历Map


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

public class MapTest2 {
	public static void main(String[] args) {
		HashMap hashMap = new HashMap();
		hashMap.put("1", "a");
		hashMap.put("2", "b");
		hashMap.put("3", "c");
		hashMap.put("4", "d");
		hashMap.put("5", "e");
		hashMap.put("6", "f");
		Set set = hashMap.keySet();
		Iterator iter = set.iterator();
		while(iter.hasNext()){
			String key = (String)iter.next();
			String value = (String)hashMap.get(key);
			System.out.println(key+ "=" +value);
		}
	}
}

 

你可能感兴趣的:(keyset)