Looking at the documentation, the compare()
method should be used to determine the order of the two students (here, you would want to do it alphabetically). If you wanted to check for equality, you could override the equals()
method of the Comparator
. For strings, you can just use existing methods to compare the students' name fields.
public static Comparator<Student> getCompByName()
{
Comparator comp = new Comparator<Student>(){
@Override
public int compare(Student s1, Student s2)
{
s1.name.compareTo(s2.name)
}
};
return comp;
}