怎样方便的读取map的key和value

1.方法一
public void getKV(){
	Map map = new HashMap();
	map.put("key1","value1");
	map.put("key2","value2");
	Collection keys = map.keySet();
	Collection values = map.values();
	for(int i = 0; i<keys.size(); i++){
		System.out.println(keys.toArray()[i]);
		System.out.println(values.toArray()[i])
	}
}


2.方法二
public void getKV(){
	Map<String, String> m = new HashMap<String, String>();
	m.put("key1","value1");
	m.put("key2","value2");
	for(String key: m.keySet()){
		System.out.println("KEY:" + key + "  VAL:" + m.get(key));
	}
}

你可能感兴趣的:(value)