之前做项目的是有些list
public static void main(String[] args) {
List<Map> list = new ArrayList<Map>();
Map m1 = new HashMap<String, String>();
m1.put("id", 1);
m1.put("name", "刘备");
Map m2 = new HashMap<String, String>();
m2.put("id", 2);
m2.put("name", "关羽");
Map m3 = new HashMap<String, String>();
m3.put("id",3);
m3.put("name", "张飞");
list.add(m2);
list.add(m1);
list.add(m3);
System.out.println("初始化=============");
for (Map map : list) {
System.out.println(map.toString());
}
System.out.println("end");
List<Map> result = process_intd(list, "id");
System.out.println("result===================");
for (Map map : result) {
System.out.println(map.toString());
}
System.out.println("end");
}
// 按照int排序listMap--3 2 1 。
public static List<Map> process_int(List<Map> data,final String arg) {
List<Map> returnList = new ArrayList<Map>();
List<Map> dsList = new ArrayList<Map>();
Collections.sort(data, new Comparator<Map>() {
public int compare(Map o1, Map o2) {
return (Integer) o1.get(arg) > (Integer) o2.get(arg) ? ((Integer) o1
.get(arg) == (Integer) o2.get(arg) ? 0 : -1) : 1;
}
});
returnList.addAll(data);
return returnList;
}
// 123
public static List<Map> process_intd(List<Map> data, final String arg) {
List<Map> returnList = new ArrayList<Map>();
Collections.sort(data, new Comparator<Map>() {
public int compare(Map o1, Map o2) {
return (Integer) o1.get(arg) < (Integer) o2.get(arg) ? ((Integer) o1
.get(arg) == (Integer) o2.get(arg) ? 0 : -1) : 1;
}
});
returnList.addAll(data);
return returnList;
}