I'm attempting to write a method where I need to compare two objects from a linked list of address objects. The method should compare the lastName field for the two objects:
*If the calling object's last name is alphabetically before the object passed to the method, I want the method to return a -1.
*If the calling object's last name is alphabetically after the object passed to the method, I want the method to return a 1.
*If the calling object's last name is alphabetically equivalent to the object passed to the method, I want the method to return a 0.
So I understand that the method should take an object and return an integer. I don't have much experience with comparing objects - just primitive data types so far. The fact that they need to be compared alphabetically really throws me. Does Java have some way to compare string fields within objects?
*If the calling object's last name is alphabetically before the object passed to the method, I want the method to return a -1.
*If the calling object's last name is alphabetically after the object passed to the method, I want the method to return a 1.
*If the calling object's last name is alphabetically equivalent to the object passed to the method, I want the method to return a 0.
So I understand that the method should take an object and return an integer. I don't have much experience with comparing objects - just primitive data types so far. The fact that they need to be compared alphabetically really throws me. Does Java have some way to compare string fields within objects?