Comparing two objects in an Arraylist by a specific attribute
843789May 27 2009 — edited May 28 2009Hello 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.