Map的常见遍历方式

[java] view plain copy
  1. Map<String,String>map=newHashMap();
  2. for(Map.Entryentry:map.entrySet()){
  3. Objectkey=entry.getKey();
  4. }

[java] view plain copy
  1. Maphashmap=newHashMap();
  2. Setset=hashmap.entrySet();
  3. Iteratoriterator=set.iterator();
  4. while(iterator.hasNext(){
  5. Map.Entrymapentry=(Map.Entry)iterator.next();
  6. System.out.println(mapentry.getkey()+"/"+mapentry.getValue());
  7. }

[java] view plain copy
  1. Setkeys=map.keySet();
  2. if(keys!=null){
  3. Iteratoriterator=keys.iterator();
  4. while(iterator.hasNext()){
  5. Objectkey=iterator.next();
  6. Objectvalue=map.get(key);
  7. }
  8. }



你可能感兴趣的:(map)