Java Map Sort sortByValue( Map map)

Here you can find the source of sortByValue( Map map)

Description

sort By Value

License

Open Source License

Declaration

public static <K, V extends Comparable<? super V>> List<Map.Entry<K, V>> sortByValue(
            Map<K, V> map) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    public static <K, V extends Comparable<? super V>> List<Map.Entry<K, V>> sortByValue(
            Map<K, V> map) {

        List<Map.Entry<K, V>> sortedEntries = new ArrayList<Map.Entry<K, V>>(
                map.entrySet());/*  w ww  . j  av a2  s .  co m*/

        Collections.sort(sortedEntries, new Comparator<Map.Entry<K, V>>() {
            @Override
            public int compare(Map.Entry<K, V> e1, Map.Entry<K, V> e2) {
                return e2.getValue().compareTo(e1.getValue());
            }
        });

        return sortedEntries;
    }
}

Related

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