Consider using the Comparator
interface described here which uses generics so you can avoid casting Object
to Student
.
As Eugene Retunsky said, your first part is the correct way to compare String
s. Also if the lastName
s are equal I think you meant to compare firstName
s, in which case just use compareTo
in the same way.