I want to develop a sorting demo for car list. I am using data table to display car list. Now actually I want to sort the list by car color. Here it is not sort by alphabeti
In Java 8 you can do something like this:
You first need an Enum:
public enum Color {
BLUE, YELLOW, RED
}
Car class:
public class Car {
Color color;
....
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
}
And then, using your car list, you can simply do:
Collections.sort(carList, Comparator:comparing(CarSort::getColor));