-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckSort.java
More file actions
36 lines (32 loc) · 920 Bytes
/
CheckSort.java
File metadata and controls
36 lines (32 loc) · 920 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
34
35
36
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class CheckSort {
static class Demo{
float p;
Demo(float p) {
this.p = p;
}
public String toString() {
return this.p + "";
}
}
public static void main(String args[]) {
Demo d1 = new Demo(5);
Demo d2 = new Demo(2);
Demo d3 = new Demo(6);
Demo d4 = new Demo(7);
Demo d5 = new Demo(5);
ArrayList<Demo> al = new ArrayList<>();
al.add(d1);al.add(d2);al.add(d3);al.add(d4);al.add(d5);
Collections.sort(al, new Comparator<Demo>() {
@Override
public int compare(Demo o1, Demo o2) {
if((o1.p-o2.p) == 0) return 0;
return (int) 1;
}
});
System.out.println(al);
System.out.println(d1.p-d5.p);
}
}