谁能给个这个list最简单的排序,想不出最简单的实现

科比请留步 2016-08-17 10:56:20
public class Test {
public static void main(String[] args) {
List<Map<String,Integer>> list = new ArrayList<Map<String,Integer>>();
Map<String,Integer> map1 = new HashMap<String, Integer>();
map1.put("sort", 4);
list.add(map1);

Map<String,Integer> map2 = new HashMap<String, Integer>();
map2.put("sort", 1);
list.add(map2);

Map<String,Integer> map3 = new HashMap<String, Integer>();
map3.put("sort", 3);
list.add(map3);

Map<String,Integer> map4 = new HashMap<String, Integer>();
map4.put("sort", 2);
list.add(map4);
System.out.println(list);

}

}

根据1234排序
...全文
257 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
iamjsber 2016-08-17
  • 打赏
  • 举报
回复
collections 有一个sort方法 很好用
解开者 2016-08-17
  • 打赏
  • 举报
回复
		Collections.sort(list, new Comparator<Map<String, Integer>>() {
			@Override
			public int compare(Map<String, Integer> a, Map<String, Integer> b) {
				return a.get("sort") - b.get("sort");
			}
		});
科比请留步 2016-08-17
  • 打赏
  • 举报
回复
已经解决,简单实现

62,628

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧