200. Sorting a map
Let’s assume that we have the following map:
public class Car {
private final String brand;
private final String fuel;
private final int horsepower;
...
}
Map<Integer, Car> cars = Map.of(
1, new Car("Dacia", "diesel", 350),
2, new Car("Lexus", "gasoline", 350),
3, new Car("Chevrolet", "electric", 150),
4, new Car("Mercedes", "gasoline", 150),
5, new Car("Chevrolet", "diesel", 250),
6, new Car("Ford", "electric", 80),
7, new Car("Chevrolet", "diesel", 450),
8, new Car("Mercedes", "electric", 200),
9, new Car("Chevrolet", "gasoline", 350),
10, new Car("Lexus", "diesel", 300)
);
Next, we want to sort this map into a List<String>
, as follows:
- If the horsepower values are different, then sort in descending...