java中遍歷HashMap

Map.Entry 遍歷



for(Map.Entry<String, String> entry:map.entrySet()){    
  //todo   
}   
 spa


迭代器迭代Iterator


Set set = map.entrySet();         
Iterator i = set.iterator();         
while(i.hasNext()){      
     Map.Entry<String, String> entry1=(Map.Entry<String, String>)i.next();    
    //todo
}   
 it

 


用keySet()迭代 


Iterator it=map.keySet().iterator();    
while(it.hasNext()){    
   //todo
 }   遍歷

 


用entrySet()迭代 
 


Iterator it=map.entrySet().iterator();           


while(it.hasNext()){    
        Map.Entry entry = (Map.Entry)it.next();           
     //todo      
                       
}   map

相關文章
相關標籤/搜索