Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
46 lines (36 loc) · 1.05 KB

File metadata and controls

46 lines (36 loc) · 1.05 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* Created by yahier on 17/1/26.
* 测试对象排序。分别给
*/
public class SortObj {
public static void main(String[] args){
new SortObj().test1();
}
void test1() {
People p1 = new People(12, "yahier");
People p2 = new People(2, "soso");
People p3 = new People(24, "bingo");
List<People> list = new ArrayList<>();
list.add(p1);
list.add(p2);
list.add(p3);
Collections.sort(list, new Comparator<People>() {
@Override
public int compare(People a, People b) {
//这三种方法都通过测试啦。
//return a.getName().compareTo(b.getName());
//return a.getAge()-b.getAge();
return a.compareTo(b);
}
});
for(int i=0;i<list.size();i++){
System.out.println(list.get(i).getAge());
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.