Java Map Sort sortHashMapByValuesD(HashMap passedMap)

Here you can find the source of sortHashMapByValuesD(HashMap passedMap)

Description

sort Hash Map By Values D

License

Open Source License

Declaration

public static LinkedHashMap sortHashMapByValuesD(HashMap passedMap) 

Method Source Code

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

import java.util.*;

public class Main {
    public static LinkedHashMap sortHashMapByValuesD(HashMap passedMap) {
        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();

            while (keyIt.hasNext()) {
                Object key = keyIt.next();
                String comp1 = passedMap.get(key).toString();
                String comp2 = val.toString();

                if (comp1.equals(comp2)) {
                    passedMap.remove(key);
                    mapKeys.remove(key);
                    sortedMap.put((String) key, (Double) val);
                    break;
                }/*from   w  w  w.j  av a2  s.c  om*/

            }

        }
        return sortedMap;
    }
}

Related

  1. sortedString(Map c)
  2. sortedString(Map c)
  3. sortedTable(Map map)
  4. sortedView(Map original, int numItems)
  5. sortEntries(Map map, Comparator> comparator)
  6. sortingHelperSessions(String column, Map sortParams)
  7. sortKeysByValue(final Map m)
  8. sortKeysDesc(HashMap> hash)
  9. sortKeyValuePairByValue( Map map)