Collections.sort对数组进行排序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Collections.sort(countType, new Comparator<Map<String, String>>() {
@Override
public int compare(Map<String, String> o1, Map<String, String> o2) {
String occupy1 = o1.get("occupy");
String substring1 = occupy1.substring(occupy1.indexOf("{") + 1, occupy1.length() - 1);
String occupy2 = o2.get("occupy");
String substring2 = occupy2.substring(occupy2.indexOf("{") + 1, occupy2.length() - 1);
int m1 = Integer.parseInt(substring1);
int m2 = Integer.parseInt(substring2);
if (m1 > m2) {
//m1在m2后面
return 1;
} else if (m1 < m2) {
//m1在m2前面
return -1;
} else {
Toast.makeText(FYInspecRequireActivity.this, "返回数据存在问题,occupy有相同的,我无法解析", Toast.LENGTH_SHORT).show();
return 0;
}
}
});