码迷,mamicode.com
首页 > 编程语言 > 详细

List<Map>去重排序

时间:2014-12-15 11:43:22      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   sp   for   on   数据   

 数据格式

[
{
"id":"d3e8a9d6-e4c6-4dd8-a94f-07733d3c1b59",
"parentId":"6d460008-38f7-479d-b6d1-058ebc17dae3",
"myorder":1,
"name":"任务一"
},
{
"id":"6d460008-38f7-479d-b6d1-058ebc17dae3",
"parentId":"33978737-c722-4339-88a1-a9829dd4bca2",
"myorder":1,
"name":"项目一"
},
{
"id":"33978737-c722-4339-88a1-a9829dd4bca2",
"parentId":"5461ed61-543c-4ea1-9cb5-17b008e093a0",
"myorder":1,
"name":"课题一"
},
{
"id":"5461ed61-543c-4ea1-9cb5-17b008e093a0",
"parentId":"57e06272-eab4-4920-ae6a-25e055374851",
"myorder":1,
"name":"电子教案"
},
{
"id":"8d0723db-9087-4c83-8d0e-ab7f24ddf066",
"parentId":"6d460008-38f7-479d-b6d1-058ebc17dae3",
"name":"任务二",
"myorder":2
}
]

 

 1 //去重复的
 2 
 3 for ( int i = 0 ; i < newList.size() - 1 ; i ++ ) { 
 4 for ( int j = newList.size() - 1 ; j > i; j -- ) { 
 5 if (newList.get(j).equals(newList.get(i))) { 
 6 newList.remove(j); 
 7 } 
 8 } 
 9 }
10 
11 
12 
13 //排序
14 this.sort(newList);
15 
16 myorder为排序号
17 
18 public void sort(List<Map<String, Object>> list) {
19 Collections.sort(list, new Comparator<Map<String, Object>>(){
20 public int compare(Map<String, Object> o1, Map<String, Object> o2) {
21 return (Integer)o1.get("myorder")>(Integer)o2.get("myorder")?1:( (Integer)o1.get("myorder")==(Integer)o2.get("myorder")?0:-1);
22 } 
23 });
24 }

 

List<Map>去重排序

标签:style   blog   io   ar   color   sp   for   on   数据   

原文地址:http://www.cnblogs.com/libaoting/p/4164346.html

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