对Map按照value由大到小排序

  (tf_idf_each_words为一个已知的待排序的map)

List<Map.Entry<String,Double>> list = new ArrayList<Map.Entry<String,Double>>(tf_idf_each_words.entrySet());

 Collections.sort(list, new Comparator<Map.Entry<String, Double>>() {  
   public int compare(Entry<String, Double> o1,  
           Entry<String, Double> o2) {  
       return o2.getValue().compareTo(o1.getValue());  
   }  
});  
for(Map.Entry<String,Double> mapping:list){ 
tf_idf_each_words_sort.put(mapping.getKey(), mapping.getValue());
              


         }

你可能感兴趣的:(对Map按照value由大到小排序)