-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.java
More file actions
33 lines (28 loc) · 784 Bytes
/
Copy pathtest.java
File metadata and controls
33 lines (28 loc) · 784 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
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
class Cars {
String name;
int model;
int sales;
public Cars(String name, int model, int sales) {
this.name = name;
this.model = model;
this.sales = sales;
}
@Override
public String toString() {
return name + " " + model + " " + sales;
}
}
public class test {
public static void main(String[] args) {
List<Cars> cars = new ArrayList<>();
cars.add(new Cars("Toyota", 85, 200));
cars.add(new Cars("Mitsubishi", 95, 350));
cars.add(new Cars("Nissan", 90, 250));
Collections.sort(cars, Comparator.comparingInt(c -> c.sales));
System.out.print(cars);
}
}