I've only used Comparators until now in order to sort in Array.sort(array,comparator).
I would like to impose order on a class that I am creating. Lets say I have a class Person and it has a lot of fields, for example I want to compare by first name.
I have a class that represents a PersonCollections. I would like to create an array list that self sorts itself in insertion. Lets say I have an ArrayList called people as a field and in insertion I would like to use a Comparator for example:
public void insert (Person p){
for(int i = 0; i < people.size(); i++){
if (people.get(i) > p){
//Do something
}
}
}
For now I have am implementing the Comparator interface and the compare method but it still doesn't recognize the > symbol on a Person class.
I would like to add that I am aware that by letting Person implements comparable I can get a good result but it is impotent for me to use Comparator here.
Thanks