Java HashMap按value排序方法
Java HashMap按value排序方法,代码如下:
public static void main(String[] args) { List\<Map.Entry\<String, Integer\>\> list = new ArrayList\<Map.Entry\<String, Integer\>\>(area2no.entrySet()); Collections.sort(list, new Comparator\<Map.Entry\<String, Integer\>\>() { public int compare(Entry\<String, Integer\> arg0, Entry\<String, Integer\> arg1) { return arg0.getValue() - arg1.getValue(); } }); for(int i=0; i\< list.size(); i++){ Entry\<String, Integer\> entry = list.get(i); System.out.println(entry.getKey() + "("" + entry.getKey() + "", " + entry.getValue() + ", "" + map.get(entry.getKey()) + ""),"); } }