In Java,
Class StudentProgress
{
String Name;
String Grade;
/* CTOR goes here */
}
main class
{
main method()
{
StudentProgress arrayofObjects[100000];
}
}
If the Grades are like D-,C-,B-,A-,A,B,C,D,A+,B+,C+,D+. I need to sort these objects how can I do it efficiently
Thanks in advance
Your best approach is to make your class implement
Comparable. Something like this will work:Then to sort, you simply use the
Arrays.sort()method:If you don’t want your class to implement this interface, you can provide a stand-alone
Comparatorto the sort call