I have a list/collection of objects that may or may not have the same property values. What\'s the easiest way to get a distinct list of the objects with equal properties? I
You can use a Set. There's couple of implementations:
HashSet uses an object's hashCode and equals.TreeSet uses compareTo (defined by Comparable) or compare (defined by Comparator). Keep in mind that the comparison must be consistent with equals. See TreeSet JavaDocs for more info.Also keep in mind that if you override equals you must override hashCode such that two equals objects has the same hash code.