I have a Fruit model class:
public class Fruit{
private String name;
private String color;
public Fruit(String name, color){
this.name = name;
this.color = color;
}
public getName(){
return name;
}
public getColor(){
return color;
}
}
Then, I created a list of fruits:
List<Fruit> fruits = new ArrayList<Fruit>();
fruits.add(new Fruit("Orange","orange"));
fruits.add(new Fruit("Strawberry","red"));
fruits.add(new Fruit("Apple","green"));
fruits.add(new Fruit("Banana","yellow"));
Now, I would like to sort the fruits elements in alphabetical order in terms of fruit name . How can I efficiently sort the fruits list?