1.遍历key,value
- Set
Map<String, String> fieldsMap = new HashMap<>();
Set<String> keySet = fieldsMap.keySet();
for (String key : keySet) {
System.out.println(key + " " + fieldsMap.get(key));
}
- Iterator
Iterator iterator = keyset.iterator();
while(iterator.hasNext()){
Object key = iterator.next();
System.out.println(key+"-"+hashMap.get(key));
}
- entrySet()
Set set = hashMap.entrySet();
for(Object key:set){
Map.Entry entry = (Map.Entry) key;
System.out.println(entry.getKey()+"-"+entry.getValue());
}
- Map.Entry
Set set1 = hashMap.entrySet();
Iterator iterator1 = set1.iterator();
while(iterator1.hasNext()){
Object itset = iterator1.next();
Map.Entry entry = (Map.Entry) itset;
System.out.println(entry.getKey()+"-"+entry.getValue());
}
标签:Map,iterator,System,key,entry,Entry
From: https://www.cnblogs.com/lwx11111/p/17636005.html