Here you can find the source of sortHashMapByKeys(HashMap passedMap, boolean ascending)
Parameter | Description |
---|---|
passedMap | a parameter |
ascending | a parameter |
public static ArrayList sortHashMapByKeys(HashMap passedMap, boolean ascending)
//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; } }