遍歷map-------囧

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

  {  
  Map.Entry entry = (Map.Entry) it.next();  
  Object key = entry.getKey();  
  Object value = entry.getValue();  
  }

 

 

 Map<Short, Integer > mmm =new HashMap<Short, Integer >();
mmm.put((short)0, 2);
mmm.put((short)3, 2);
Set<Entry<Short, Integer>> params =  mmm.entrySet();
for( int i = 0 ; i < params.size(); i++){
    Entry[] entry =  params.toArray( new Entry[0]);
   System.out.println(entry[i].getKey() + " : " + entry[i].getValue());    
}
//只支持jdk1.5以上
for (Map.Entry entry : params) {    
    System.out.println(entry.getKey() + " : " + entry.getValue());    
} 

 

你可能感兴趣的:(map)