for-each遍历Map



import java.util.HashMap;
import java.util.Map;



public class Main {
	
	public static void main(String[] args) {
		Map mymap = new HashMap();
		mymap.put("a", 1);
		mymap.put("b", 2);
		mymap.put("c", 3);
		mymap.put("c", 44444);
		
		for(Map.Entry per : mymap.entrySet()) {
			System.out.printf("key:%s  value:%s\n", per.getKey(), per.getValue());
		}
		System.out.printf("==============================\n");
		for(String key : mymap.keySet()) {
			System.out.printf("key:%s  value:%s\n", key, mymap.get(key));
		}

	}
}

/*

key:b  value:2
key:c  value:44444
key:a  value:1
==============================
key:b  value:2
key:c  value:44444
key:a  value:1

*/


你可能感兴趣的:(java,java.util)