首页 > 其他 > 详细

工具类

时间:2018-09-25 15:55:04      阅读:152      评论:0      收藏:0      [点我收藏+]

//map转List
private List<CityForQmi> mapTransitionList(Map<String, CityForQmi> map) {

List<CityForQmi> list = new ArrayList<>();
Iterator item = map.entrySet().iterator(); // 获得map的Iterator
while (item.hasNext()) {
Entry<String, CityForQmi> entry = (Entry) item.next();
list.add(entry.getValue());
}
return list;
}

 

//Map降序排序
private <K, V extends Comparable<? super V>> Map<K, V> sortByValueDescending(Map<K, V> map)
{
List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet());
Collections.sort(list, (o1, o2) -> {
int compare = (o1.getValue()).compareTo(o2.getValue());
return -compare;
});

Map<K, V> result = new LinkedHashMap<>();
for (Map.Entry<K, V> entry : list) {
result.put(entry.getKey(), entry.getValue());
}
return result;
}

工具类

原文:https://www.cnblogs.com/astech/p/9699859.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!