1.Map循环的几种方式
Map<String,String> map = new HashMap<String, String>();
//通过key Set<T> key = map.keySet()
for(String key:map.keySet()){
System.out.println("key="+key+" value="+map.get(key));
}
//key和value都循环
for(Map.Entry<String,String> entry : map.entrySet()){
System.out.println("key="+entry.getKey()+" value="+entry.getValue());
}
//通过迭代器
Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator();
while (iterator.hasNext()){
Map.Entry<String, String> entry = iterator.next();
System.out.println("key="+entry.getKey()+" value="+entry.getValue());
}
//只循环value
for(String value : map.values()){
System.out.println("value="+value);
}