I made a list of Animals as follows :
ArrayList<Animal> animals = new ArrayList<Animal>();
animals.add(new Animal(1, "animal1", 50, "10 Janvier 2016", "Noir", 4, true));
animals.add(new Animal(2, "animal2", 50, "10 Janvier 2016", "Noir", 4, true));
animals.add(new Animal(3, "animal3", 50, "10 Janvier 2016", "Noir", 4, true));
animals.add(new Animal(4, "animal4", 50, "10 Janvier 2016", "Noir", 4, true));
animals.add(new Animal(5, "animal5", 50, "10 Janvier 2016", "Noir", 4, true));
I want to sort my list of animals in ArrayList by their ID. From what i've seen i have to use a comparator.
This is what i created so far...
public class ComparatorAnimal implements Comparator<Animal> {
public int compare(Animal animals.get(0), Animal animals.get(1) {
return animals.get(0).idAnimal - animals.get(1).idAnimal;
}
Comperatorinterface actually tells you the signature of the method that you do have to implement. If you don´t have a method with this signature inside your class then it would not compile, which i guess is the case right now. Well and you can´t name your variables likeanimals.get(0)