List of utility methods to do Map Sort
Map | sortByValue(Map sort By Value List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet()); Collections.sort(list, (o1, o2) -> -((o1.getValue()).compareTo(o2.getValue()))); Map<K, V> result = new LinkedHashMap<>(); for (Map.Entry<K, V> entry : list) { result.put(entry.getKey(), entry.getValue()); return result; |
Map | sortByValue(Map sort By Value return sortByValue(map, false);
|
Map | sortByValue(Map Sort a map by value (increasing order) return sortByValue(map, new Comparator<Entry<K, V>>() { @Override public int compare(Entry<K, V> o1, Entry<K, V> o2) { return (o1.getValue()).compareTo(o2.getValue()); }); |
Map | sortByValue(Map sort By Value List<Map.Entry<K, V>> entriesInList = extractEntriesSortedByValue(map); Map<K, V> result = new LinkedHashMap<K, V>(); for (Map.Entry<K, V> entry : entriesInList) { result.put(entry.getKey(), entry.getValue()); return result; |
Map | sortByValue(Map Sort the value in the map and swap the pair of view and its rank value in descending order. return sortByValue(map, true);
|
Map | sortByValue(Map Sorts a map by its values. int s2 = 1; if (descending) s2 = -1; final int sign = s2; List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet()); Collections.sort(list, new Comparator<Map.Entry<K, V>>() { @Override public int compare(Entry<K, V> o1, Entry<K, V> o2) { ... |
LinkedHashMap | sortByValue(Map Sorts map by value (http://stackoverflow.com/a/2581754) List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet()); Collections.sort(list, new Comparator<Map.Entry<K, V>>() { @Override public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) { if (asc) { return (o1.getValue()).compareTo(o2.getValue()); } else { return (o2.getValue()).compareTo(o1.getValue()); ... |
Map | sortByValue(Map Sort a map by its values List<Entry<S, T>> list = new LinkedList<Entry<S, T>>(map.entrySet()); Collections.sort(list, (o1, o2) -> o1.getValue().compareTo(o2.getValue())); Map<S, T> result = new LinkedHashMap<S, T>(); for (Entry<S, T> entry : list) { result.put(entry.getKey(), entry.getValue()); return result; |
Map | sortByValue(Map sort By Value List list = new LinkedList(map.entrySet()); Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { return ((Comparable) ((Map.Entry) (o1)).getValue()).compareTo(((Map.Entry) (o2)).getValue()); }); Map<String, String> result = new LinkedHashMap(); for (Iterator it = list.iterator(); it.hasNext();) { ... |
Map | sortByValueAscending(Map sort By Value Ascending return sortByValue(map, (o1, o2) -> o1.getValue().compareTo(o2.getValue()));
|