Java HashMap Sort sortHashMapByKeys(HashMap passedMap, boolean ascending)

Here you can find the source of sortHashMapByKeys(HashMap passedMap, boolean ascending)

Description

sort Hash Map By Keys

License

LGPL

Parameter

Parameter Description
passedMap a parameter
ascending a parameter

Declaration

public static ArrayList sortHashMapByKeys(HashMap passedMap, boolean ascending) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.util.ArrayList;

import java.util.Collections;
import java.util.HashMap;

import java.util.Iterator;

import java.util.List;

public class Main {
    /**//from ww  w.  j  ava 2s  . c o  m
     * @param passedMap
     * @param ascending
     * @return
     */
    public static ArrayList sortHashMapByKeys(HashMap passedMap, boolean ascending) {

        List mapKeys = new ArrayList(passedMap.keySet());
        Collections.sort(mapKeys);

        if (!ascending)
            Collections.reverse(mapKeys);

        ArrayList result = new ArrayList();
        Iterator keyIt = mapKeys.iterator();
        while (keyIt.hasNext()) {
            Object key = keyIt.next();
            result.add(passedMap.get(key));

        }
        return result;
    }
}

Related

  1. getSortedHashMapKeyset(Map sorting)
  2. getSortedLinkedHashMap(Map bitCounts, Comparator comparator)
  3. sortByComparator(HashMap unsortMap, final boolean ascendingorder)
  4. sortByValue(HashMap map)
  5. sortedScoreMap(HashMap unSortedMap)
  6. sortHashMapByValues( HashMap> passedMap, String key0)
  7. sortHashMapByValues(HashMap passedMap, boolean ascending)
  8. sortHashMapByValues(HashMap passedMap)
  9. sortMapByValue(HashMap map, final int sort)

  10. HOME | Copyright © www.java2s.com 2016