Java Utililty Methods Map Sort

List of utility methods to do Map Sort

Description

The list of methods to do Map Sort are organized into topic(s).

Method

LinkedHashMapsortHashMapByValuesD(HashMap passedMap)
sort Hash Map By Values D
List mapKeys = new ArrayList(passedMap.keySet());
List mapValues = new ArrayList(passedMap.values());
Collections.sort(mapValues);
LinkedHashMap sortedMap = new LinkedHashMap();
Iterator valueIt = mapValues.iterator();
while (valueIt.hasNext()) {
    Object val = valueIt.next();
    Iterator keyIt = mapKeys.iterator();
...
StringsortingHelperSessions(String column, Map sortParams)
sorting Helper Sessions
String link_beginning = "<a href=\"gojara-activeSessions.jsp?sortby=";
return helpMe(column, sortParams, link_beginning);
java.util.ListsortKeysByValue(final Map m)
a generic method that returns the list of keys sorted by value.
java.util.List<Object> keys = new ArrayList<Object>();
keys.addAll(m.keySet());
Collections.sort(keys, new Comparator<Object>() {
    public int compare(Object key1, Object key2) {
        Object v1 = m.get(key1);
        Object v2 = m.get(key2);
        if (v1 == null) {
            return (v2 == null) ? 0 : 1;
...
int[]sortKeysDesc(HashMap> hash)
Sort the integer keys in a HashMap from highest to lowest.
Collection<Integer> keys = new ArrayList<Integer>();
Iterator it = hash.keySet().iterator();
while (it.hasNext()) {
    int wc = Integer.parseInt(it.next().toString());
    keys.add(wc);
int[] iKeys = Iv2s(keys);
Arrays.sort(iKeys);
...
List>sortKeyValuePairByValue( Map map)
Utility method to sort the keys and values of a map by their value.
List<Map.Entry<K, V>> entries = new ArrayList<Map.Entry<K, V>>(map.entrySet());
Collections.sort(entries, new Comparator<Map.Entry<K, V>>() {
    @Override
    public int compare(Entry<K, V> o1, Entry<K, V> o2) {
        if (!o1.getValue().equals(o2.getValue())) {
            return (o1.getValue()).compareTo(o2.getValue());
        return o1.getKey().compareTo(o2.getKey());
...
LinkedHashMapsortMap(final Map map, final Comparator> comparator)
Sort a map by supplied comparator logic.
List<Map.Entry<K, V>> mapEntries = new LinkedList<Map.Entry<K, V>>(map.entrySet());
Collections.sort(mapEntries, comparator);
LinkedHashMap<K, V> result = new LinkedHashMap<K, V>(map.size() + (map.size() / 20));
for (Map.Entry<K, V> entry : mapEntries) {
    result.put(entry.getKey(), entry.getValue());
return result;
voidsortMap(LinkedHashMap map, Comparator> c)
sort Map
List<Map.Entry<K, V>> entries = new ArrayList<>(map.entrySet());
entries.sort(c);
map.clear();
for (Map.Entry<K, V> e : entries) {
    map.put(e.getKey(), e.getValue());
MapsortMap(Map oldMap)
sort Map
ArrayList<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(oldMap.entrySet());
Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
    @Override
    public int compare(Map.Entry<String, Integer> arg0, Map.Entry<String, Integer> arg1) {
        return arg0.getValue() - arg1.getValue();
});
Map newMap = new LinkedHashMap();
...
MapsortMap(Map oldMap, final boolean asc)
sort Map
if (null == oldMap) {
    return null;
ArrayList<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(oldMap.entrySet());
Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
    public int compare(Map.Entry<String, Integer> arg0, Map.Entry<String, Integer> arg1) {
        if (asc) {
            return arg0.getValue() - arg1.getValue();
...
List>sortMap(Map map, int k)
sort Map
List<Map.Entry<Integer, Double>> list = new ArrayList<Map.Entry<Integer, Double>>(map.entrySet());
Collections.sort(list, new Comparator<Map.Entry<Integer, Double>>() {
    @Override
    public int compare(Map.Entry<Integer, Double> arg0, Map.Entry<Integer, Double> arg1) {
        return (arg1.getValue().compareTo(arg0.getValue()));
});
if (k > list.size())
...