/* Pgm to display the student details after sorting them with respect to their GPA using the compareTo() method . . .*/
Name = Dan Costello ID = 104 GPA = 2.3
Name = William Costigan ID = 102 GPA = 2.8
Name = Jamie Sullivan ID = 103 GPA = 3.6
Name = Mike Larry ID = 101 GPA = 4.0
BUILD SUCCESSFUL (total time: 0 seconds)
Ranjitha Serginaro wrote:
Object studentArray=studentSet.toArray(); /* Why is 'Object' class used here instead of 'Student' class to create the 'studentArray' object.
Also what does toArray() method do?*/
becasue java.util.AbstractCollection.toArray() returns Object . If you want to return Student then you need to consider generic version - T toArray(T a)
for more detail : go through JavaDoc.
and couple of suggestion :
1.dont use double for calculation, it may loose precision in result . So, consider java.lang.Double.compare(double, double)
2.use generic collection instead of error prone raw collection .
in this way you can do clean array conversion as below code
subject: Comparable interface. Doubt in ComparableTest class. Please find the question as comment below.