jackroomage 发表于 2013-1-26 13:25:04

对hashmap按值排序怎么做?

问题:对hashmap按值排序怎么做?
 
方法1、
 
 public static void main(String[] args){
  Map map=new HashMap();
  map.put("d", 761);
  map.put("g", 7);
  map.put("a", 7612);
  map.put("c", 34);
  
  int value=0;
     String maxKey = null;
     List list=new ArrayList();
    
  Iterator ite=map.entrySet().iterator();
  while(ite.hasNext()){
           Map.Entry entry =(Map.Entry)ite.next();
            value = Integer.parseInt(entry.getValue().toString());
            list.add(entry.getValue());
            Collections.sort(list);
     }
      for(int i=0;i<list.size();i++){
   System.out.println(list.get(i));
  }
 }
页: [1]
查看完整版本: 对hashmap按值排序怎么做?