I have a arraylist and it contains a 100 employee object and each object contains “Name” and “Salary”. We need to find the Max salaried employeee from the Object .Please let me know what is the way .
I thought of implementing compareTo and equals Method is it right , and also using Collections.sort Is it the right way or is there any other way
If the language is Java, then either implement the Comparable interface (just
compareTo–no need forequals) for the objects in the array list and callCollections.sort(arraylist), or else write a Comparator and callCollections.sort(arraylist, comparator). The latter is more flexible, as it doesn’t require your objects to always be sorted by salary.