Here you can find the source of sortMapByBDValue(Map
public static <T> Map<T, BigDecimal> sortMapByBDValue(Map<T, BigDecimal> oriMap)
//package com.java2s; //License from project: Open Source License import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; public class Main { public static <T> Map<T, BigDecimal> sortMapByBDValue(Map<T, BigDecimal> oriMap) { Map<T, BigDecimal> sortedMap = new LinkedHashMap<T, BigDecimal>(); if (oriMap != null && !oriMap.isEmpty()) { List<Map.Entry<T, BigDecimal>> entryList = new ArrayList<Map.Entry<T, BigDecimal>>(oriMap.entrySet()); Collections.sort(entryList, new Comparator<Map.Entry<T, BigDecimal>>() { public int compare(Entry<T, BigDecimal> entry1, Entry<T, BigDecimal> entry2) { BigDecimal value1 = entry1.getValue(); BigDecimal value2 = entry2.getValue(); return value2.compareTo(value1); }//from w w w .j a v a 2s . co m }); Iterator<Map.Entry<T, BigDecimal>> iter = entryList.iterator(); Map.Entry<T, BigDecimal> tmpEntry = null; while (iter.hasNext()) { tmpEntry = iter.next(); sortedMap.put(tmpEntry.getKey(), tmpEntry.getValue()); } } return sortedMap; } }