Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

对HashMap 进行排序

$
0
0
	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 ;
	}

作者:honglei_zh 发表于2013-3-15 18:46:19 原文链接
阅读:59 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>