Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing two objects of a linked list

Status
Not open for further replies.

laina222

Technical User
Sep 7, 2001
172
US
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?
 
java.lang.String.compareTo( java.lang.String)

-pete
I just can't seem to get back my IntelliSense
 
isn't that to compare a String to another String? what if it's an object that's comprised of many Strings?
thanks!
 
yes,

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:

I assumed the lastName field was a String object since you didn't indicate otherwise.


-pete
I just can't seem to get back my IntelliSense
 
the lastName field is a String within another object. sorry for the confusion!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top