map sort
来源:互联网 发布:linux删除空文件夹 编辑:程序博客网 时间:2024/05/02 00:46
转自:http://blog.csdn.net/teedry/article/details/4844924
map中的key,value排序
如何对map进行排序呢?这就分别对map的key及value来排序。
map内部是按照hash算法存储的,有些输出的情况需要对于Map类进行排序。
- /**
- * @param h
- * @return
- * 实现对map按照value升序排序
- */
- @SuppressWarnings("unchecked")
- public static Map.Entry[] getSortedHashtableByValue(Map h) {
- Set set = h.entrySet();
- Map.Entry[] entries = (Map.Entry[]) set.toArray(new Map.Entry[set
- .size()]);
- Arrays.sort(entries, new Comparator() {
- public int compare(Object arg0, Object arg1) {
- Long key1 = Long.valueOf(((Map.Entry) arg0).getValue().toString());
- Long key2 = Long.valueOf(((Map.Entry) arg1).getValue().toString());
- return key1.compareTo(key2);
- }
- });
- return entries;
- }
- /**
- * @param h
- * @return
- * 实现对map按照key排序
- */
- @SuppressWarnings("unchecked")
- public static Map.Entry[] getSortedHashtableByKey(Map h) {
- Set set = h.entrySet();
- Map.Entry[] entries = (Map.Entry[]) set.toArray(new Map.Entry[set
- .size()]);
- Arrays.sort(entries, new Comparator() {
- public int compare(Object arg0, Object arg1) {
- Object key1 = ((Map.Entry) arg0).getKey();
- Object key2 = ((Map.Entry) arg1).getKey();
- return ((Comparable) key1).compareTo(key2);
- }
- });
- return entries;
- }
0 0
- map sort
- map/sort
- list sort map char
- map key sort
- Map sort by value
- map vector struct+sort
- List Map sort 排序
- Java 8 Map sort
- java map 按 value sort
- poj 2153 map && sort+二分
- Hadoop Map Reduce Secondary Sort
- Map-Reduce: Shuffle and Sort
- hdu Problem-1004(map+sort)
- perl中grep,sort,map用法总结
- perl中grep,sort,map用法总结
- perl中 sort map用法总结
- sort, priority_queue, set, map排序顺序
- 算法 之 位图排序 bit-map sort
- 磁盘满了MySQL会做什么?
- vs2005远程调试服务进程报R6025
- web.xml中listener的作用及使用
- Java1.7源代码学习(1)--jdk的下载
- 微信内置浏览器的JsAPI
- map sort
- Python signal模块包介绍和用法
- OpenCV参考手册之摄像头
- 深入理解Unity脚本的执行顺序(六十二)
- 设置TextView的字体颜色的方法
- fgfdgry
- 写一段程序,求1+2*2+3*3+n*n的值 Java
- Python学习笔记(20140508)
- 阴影