首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

对HashMap 开展排序

2013-03-17 
对HashMap 进行排序public static Map sortMap(Map map) {Map oneMap new LinkedHashMap() ArrayList

对HashMap 进行排序

public static Map sortMap(Map map) {Map oneMap = new LinkedHashMap() ; ArrayList<Entry<String, String>> l = new ArrayList<Entry<String, String>>(map.entrySet());Collections.sort(l, new Comparator<Object>() {public int compare(Object e1, Object e2) {int v1 = Integer.parseInt(((Entry<String, String>) e1).getValue().toString());int v2 = Integer.parseInt(((Entry) e2).getValue().toString());return  v2-v1; // 降序 v1-v2升序}});for (Entry<String, String> e : l) {oneMap.put(e.getKey(), e.getValue()) ;}return oneMap ;}

热点排行