1 | import java.util.*; |
另一种方法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
32import java.util.*;
public class TT1{
static class Point implements Comparable{
public int x;
public int y;
public Point(int x, int y){
this.x = x;
this.y = y;
}
public int compareTo(Object o){
Point p = (Point)o;
return this.x-p.x;
}
}
public static void main(String[] args){
List<Point> list = new ArrayList<>();
list.add(new Point(1, 3));
list.add(new Point(-1, 6));
list.add(new Point(4, 7));
Collections.sort(list);
for(Point p:list){
System.out.println(p.x+" "+p.y);
}
}
}
输出:
-1 6
1 3
4 7