I am trying to write a method which will take an ArrayList of Student objects and return me a String array with the names of the Students in the order of their scores (student name with highest score will be at index 0).
public static void orderStudent(List<Student> ls) {
for (Student stu : ls) {
System.out.println("Name: " + stu.getName() + ", Score: "
+ stu.getScore());
}
}
The above snippet when executed will print something like
Name: Alex, Score: 10.35
Name: Bob, Score: 11.2
Name: Charles, Score: 8.22
I want the orderStudent method to return a String array which would have the contents [Bob, Alex, Charles] Bob being the top scorer followed by Alex and Charles.
Student[], notvoid.String[]