public static class TransactionUtils { public static final int ASCENDING = 1; public static final int DESCENDING = -1; public static String getStringKeyForEntry(Object o) { Map.Entry me = (Map.Entry) o; return (String) me.getKey(); } public static int getIntValueForEntry(Object o) { Map.Entry me = (Map.Entry) o; return ((Integer) me.getValue()).intValue(); } //sort a list of Map.Entrys by their value. This assumes that the value is an Integer! //order = 1 for Ascending, order = -1 for descending. public static void sortUniqueLetterCountsByLetter(ArrayList entryList, final int order) { Collections.sort(entryList, new Comparator() { public int compare(Object o1, Object o2) { Map.Entry me1 = (Map.Entry) o1; Map.Entry me2 = (Map.Entry) o2; return (((Character)me1.getKey()) - ((Character)me2.getKey())) * order; } } ); } }