/**
* 对数据集Map进行排序
*
* @param map
* @return
* @Description:
*/
public Map<String, Integer> sortMapByStringInteger(Map<String, Integer> map)
{
Map<String, Integer> sortedMap = new LinkedHashMap<String, Integer>();
if (map != null && !map.isEmpty())
{
List<Map.Entry<String, Integer>> entryList = new ArrayList<Map.Entry<String, Integer>>(map.entrySet());
Collections.sort(entryList, new Comparator<Map.Entry<String, Integer>>()
{
public int compare(Entry<String, Integer> entry1, Entry<String, Integer> entry2)
{
if (entry1.getValue() >= entry2.getValue())
{
return 1;
}
else
{
return -1;
}
}
});
Iterator<Map.Entry<String, Integer>> iter = entryList.iterator();
Map.Entry<String, Integer> tmpEntry = null;
while (iter.hasNext())
{
tmpEntry = iter.next();
sortedMap.put(tmpEntry.getKey(), tmpEntry.getValue());
}
}
return sortedMap;
}
相关推荐
主要介绍了java如何对map进行排序,java map集合的使用详解,大家可以参考使用
对Map的key和value进行排序 对Map的key和value进行排序是Java编程中非常重要的一部分。Map是Java集合框架中的一种数据结构,用于存储键值对。然而,在实际应用中,我们经常需要对Map中的key或value进行排序,以满足...
private static SortedMap, Integer> mapSortByKey(Map, Integer> unsort_map) { TreeMap, Integer> result = new TreeMap, Integer>() Object[] unsort_key = unsort_map.keySet().toArray(); Arrays.sort...
将map按ASCII码排序,适用于将请求头的参数转为map,map内可再含有map,递归排序,无遗漏。运行demo里main方法即可进行验证。
Java Map按键排序和按值排序 可以java map按照key值排序
HashMap里面的元素是无序的,要进行排序的话只能是用TreeMap和SortedMap,java实现的map排序
map排序
C++11中有无序map即: unordered_map 可以不自动排序, 那么C++98中只有map 如何避免自动排序。
java Map转Bean Bean转Map Map排序
Map中元素存放是无序的 HashMap注意事项: 1,HashMap底层维护一个数组,我们向HashMap中所放置的对象实际上是存储在该数组当中; 2,当向HashMap中put一对键值时,它会根据key的hashCode值计算出一个位置,该位置...
java代码-使用java解决list(Map)排序的问题源代码 ——学习参考资料:仅用于个人学习使用!
主要实现Java中Map集合按值排序的几种方法。
List<map>,List<Map, Object>>,多字段组合排序。提供一个简易的思路,如果需要进行参考。
NULL 博文链接:https://sakajiaofu.iteye.com/blog/1998474
Java 对象属性map排序示例
可以将Map中的对象按照键或值进行升序或降序排列,经测试一切正常,开发者看懂后按照需求对应修改即可!
支持一个List<Map>按照MAP中的一个或者多个Key的value值的中英文来排序,自动识别字符和数字(包括[a-zA-z]?[0-9]*)排序
这里有几个很经典的Java map 集合排序的例子,大家可以试试
实现Map的排序功能,此文档针对Java开发,。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。...
java map排序,hashmap,linkedmap,treemap,hashtable