Java Map Sort sortMapByValuesDecreasing( final Map mapToSort)

Here you can find the source of sortMapByValuesDecreasing( final Map mapToSort)

Description

sort Map By Values Decreasing

License

Open Source License

Declaration

public static <K, V extends Comparable<? super V>> List<Map.Entry<K, V>> sortMapByValuesDecreasing(
            final Map<K, V> mapToSort) 

Method Source Code


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

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

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

        List<Map.Entry<K, V>> entries = new ArrayList<>(mapToSort.size());
        entries.addAll(mapToSort.entrySet());

        Collections.sort(entries, new Comparator<Map.Entry<K, V>>() {

            @Override//  w  w w  . j  a va  2  s .co  m
            public int compare(final Map.Entry<K, V> entry1, final Map.Entry<K, V> entry2) {

                return entry2.getValue().compareTo(entry1.getValue());
            }
        });

        return entries;
    }
}

Related

  1. sortMapByValue(Map oriMap)
  2. sortMapByValue(Map unsortMap, boolean highFirst)
  3. sortMapByValue(Map oriMap)
  4. sortMapByValue(Map oriMap, final boolean isDesc)
  5. sortMapByValues(Map map, final boolean inverted)
  6. sortMapByValuesDescending( Map aMap)
  7. sortMapDesc(Map map)
  8. sortMapDescByValue(Map map)
  9. sortMapDescendingByValue(Map unsortedMap)