Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Comparing two objects in an Arraylist by a specific attribute

843789May 27 2009 — edited May 28 2009
Hello all,

I'm a beginner Java programmer and I'm looking for a way to compare two objects that are stored in an Arraylist by a specific attribute.

For example, if I have an arraylist with objects in it, and every object has its own name, age, weight, whatever stored. Is there an easy way to take two specified objects, and then select what you want to compare them by and have it return the result (like "object1 is older than object2" or "object4's name comes after object2's name in alphabetical order").

It's mostly the comparing itself I don't know how to handle.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 25 2009
Added on May 27 2009
20 comments
2,990 views