Java examples for java.util:Map Operation
sort Map Descending
//package com.java2s; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Map.Entry; public class Main { public static <T extends Comparable> List<Entry<String, T>> sortMapDesc( Map<String, T> keywordMap) { List<Entry<String, T>> arrayList = new ArrayList<Entry<String, T>>( keywordMap.entrySet());//w w w.j a v a2 s .com Collections.sort(arrayList, new Comparator<Entry<String, T>>() { @Override public int compare(Entry<String, T> e1, Entry<String, T> e2) { return (e2.getValue()).compareTo(e1.getValue()); } }); return arrayList; } }