1 package com.cloud.dm;
2
3 import java.util.Collections;
4 import java.util.Comparator;
5 import java.util.List;
6 import java.util.Map;
7
8 import com.google.common.collect.Lists;
9 import com.google.common.collect.Maps;
10
11 public class TreeListTest {
12 public static void main(String[] args) {
13 List<Map<String, Object>> list = Lists.newArrayList();
14 Map<String, Object> map = Maps.newHashMap();
15 map.put("key", 201101);
16 Map<String, Object> map2 = Maps.newHashMap();
17 map2.put("key", 200010);
18 Map<String, Object> map3 = Maps.newHashMap();
19 map3.put("key", 201103);
20 list.add(map);
21 list.add(map2);
22 list.add(map3);
23 System.out.println(list);
24 Collections.sort(list, new Comparator<Map<String, Object>>() {
25 @Override
26 public int compare(Map<String, Object> o1, Map<String, Object> o2) {
27 System.out.println(o1.get("key").toString().compareTo(o2.get("key").toString()));
28 return o1.get("key").toString().compareTo(o2.get("key").toString());
29 }
30 });
31 System.out.println(list);
32 }
33 }
34
posted on 2012-03-13 18:13
周磊 阅读(1435)
评论(0) 编辑 收藏