Java examples for java.util:Map Operation
sort Map Ascending
//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>> sortMapAsc( Map<String, T> keywordMap) { List<Entry<String, T>> arrayList = new ArrayList<Entry<String, T>>( keywordMap.entrySet());//from www. j a v a2 s.co m Collections.sort(arrayList, new Comparator<Entry<String, T>>() { @Override public int compare(Entry<String, T> e1, Entry<String, T> e2) { return (e1.getValue()).compareTo(e2.getValue()); } }); return arrayList; } }