I've sorted my arraylist in descending order and now I want to print the max value. the arraylist contains a student's name and their grade. I want to print the name of the student with the highest grade. I don't need to print their grade. Just the name. this is my code
public void printStudent(){
Collections.sort(studentList);
Collections.reverse(studentList);
System.out.println("Best student is: ");
for (Student s: studentList){
System.out.println(s.toString());
}
}
Right now this prints the entire list of students and their grades however I just want to print the name of the student with the highest grade and I've tried many things but can't seem to get it to work. Thanks!