Java Map Sort sortByValue(final Map m)

Here you can find the source of sortByValue(final Map m)

Description

sort By Value

License

Apache License

Declaration

public static List sortByValue(final Map m) 

Method Source Code

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

import java.util.*;

public class Main {
    public static List sortByValue(final Map m) {
        List keys = new ArrayList();
        keys.addAll(m.keySet());/*from w w  w  .j  a  v a 2 s .  co m*/
        Collections.sort(keys, new Comparator() {
            public int compare(Object o1, Object o2) {
                Object v1 = m.get(o1);
                Object v2 = m.get(o2);
                if (v1 == null) {
                    return (v2 == null) ? 0 : 1;
                } else if (v1 instanceof Comparable) {
                    return -((Comparable) v1).compareTo(v2);
                } else {
                    return 0;
                }
            }
        });
        return keys;
    }
}

Related

  1. sortByMap(List> lists)
  2. sortByMap(Map map, int size)
  3. sortByValue( final Map map)
  4. sortByValue( Map map)
  5. sortByValue( Map map, final boolean ascendingValues)
  6. sortByValue(final Map map)
  7. sortByValue(final Map map)
  8. sortByValue(final Map map, final boolean asc)
  9. sortByValue(Map map)