Java Map Sort sortMapByValue(Map oriMap)

Here you can find the source of sortMapByValue(Map oriMap)

Description

sort Map By Value

License

Open Source License

Declaration

public static List<Map.Entry<String, Integer>> sortMapByValue(Map<String, Integer> oriMap) 

Method Source Code


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

import java.util.*;

public class Main {
    public static List<Map.Entry<String, Integer>> sortMapByValue(Map<String, Integer> oriMap) {
        if (oriMap == null || oriMap.isEmpty()) {
            return null;
        }//from  w  ww. j ava  2  s.  c om
        List<Map.Entry<String, Integer>> entries = new ArrayList<>(oriMap.entrySet());
        Collections.sort(entries, (o1, o2) -> o2.getValue() - o1.getValue());
        return entries;
    }
}

Related

  1. sortMapByValue(Map input, final boolean desc)
  2. sortMapByValue(Map map, Comparator comparator)
  3. sortMapByValue(Map map, Comparator> valueComparator)
  4. sortMapByValue(Map map, Comparator> comparator)
  5. sortMapByValue(Map map, final boolean descending)
  6. sortMapByValue(Map unsortMap, boolean highFirst)
  7. sortMapByValue(Map oriMap)
  8. sortMapByValue(Map oriMap, final boolean isDesc)
  9. sortMapByValues(Map map, final boolean inverted)