-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortTest.java
More file actions
33 lines (26 loc) · 815 Bytes
/
SortTest.java
File metadata and controls
33 lines (26 loc) · 815 Bytes
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
package _Test;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class SortTest {
public static class Person {
public int age;
public String name;
public Person(int a, String n) {
age = a;
name = n;
}
}
public static void main(String[] args) {
List<Person> plist = new ArrayList<>();
plist.add(new Person(15, "Ming"));
plist.add(new Person(34, "Jing"));
plist.add(new Person(7, "Tom"));
plist.add(new Person(12, "Jerry"));
Collections.sort(plist, (Person o1, Person o2) -> o1.age - o2.age);
for (Person person : plist) {
System.out.printf("Age:%d, Name:%s.\n", person.age, person.name);
}
}
}