Map根据value进行排序

今天需要将map按value进行排序,Google到不少解决办法,现将借鉴的解决办法记录如下:

 

Java-->

Map<String,Integer> map=new HashMap<String,Integer>(); //map.put("first",100); //map.put("second",300); //map.put("third",200); List<Map.Entry<String, Integer>> orderList=new ArrayList<Map.Entry<String, Integer>>(map.entrySet()); Collections.sort(orderList, new Comparator<Map.Entry<String, Integer>>() { public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) { return (o2.getValue()-o1.getValue()); } });

 

页面迭代显示-->

 

<s:if test="orderList.size>0"> <s:iterator value="orderList"> <s:property value="key"/> <s:property value="value"/> </s:iterator> </s:if>

 

 

 

页面显示结果:

second  300

third     200

first      100

 

It's  Over !

你可能感兴趣的:(Google,Integer,iterator)