在开发的时候,写一个搜索逻辑,用到好多排序,因为用到了map,数据都放在了map中,这时候需要排序才能用,就有了,这个排序:Map按照Value排序(升序,降序)
public class mapValueCompareSort {
public static void main(String[] args) {
HashMap<String,Double> mapDesc = new HashMap<String,Double>();
ValueComparator bvcDESC = new ValueComparator(mapDesc);
TreeMap<String,Double> sorted_map_Desc = new TreeMap<String,Double>(bvcDESC);
mapDesc.put("A",99.5);
mapDesc.put("B",67.4);
mapDesc.put("C",67.4);
mapDesc.put("D",67.3);
mapDesc.put("E",11.0);
mapDesc.put("F",-0.1);
mapDesc.put("G",0.1);
mapDesc.put("H",-99.1);
System.out.println("降序=====unsorted map: "+ma