Java Collection Sort sortByDescendingOrder(Map collection)

Here you can find the source of sortByDescendingOrder(Map collection)

Description

sort By Descending Order

License

Apache License

Declaration

public static <T> List<Map.Entry<T, Double>> sortByDescendingOrder(Map<T, Double> collection) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    public static <T> List<Map.Entry<T, Double>> sortByDescendingOrder(Map<T, Double> collection) {
        List<Map.Entry<T, Double>> list = new ArrayList<Map.Entry<T, Double>>(collection.entrySet());

        Collections.sort(list, new Comparator<Map.Entry<T, Double>>() {
            public int compare(Map.Entry<T, Double> o1, Map.Entry<T, Double> o2) {
                if (o1.getValue() > o2.getValue()) {
                    return -1;
                } else if (o1.getValue() < o2.getValue()) {
                    return 1;
                } else {
                    return 0;
                }//from  www .j av  a2 s  . c om
            }
        });

        return list;
    }
}

Related

  1. getSorted(Collection collection)
  2. isSort(Collection c)
  3. sort(Collection collection)
  4. sort(Collection collection, Comparator comparator)
  5. sort(Collection items)
  6. sortClassesByLevelOfInheritance(Collection> classes)
  7. sorted(Collection coll)
  8. sorted(Collection input)
  9. sorted(Collection coll)