码迷,mamicode.com
首页 > 其他好文 > 详细

工具类

时间:2018-09-25 16:13:11      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:cti   int   desc   new   str   return   ring   vat   result   

//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;
}

工具类

标签:cti   int   desc   new   str   return   ring   vat   result   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!