数据格式
[ { "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 }
时间: 2024-11-05 18:26:51