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? Is one collection type best suited for this purpose? For example, in C# I could do something like the following with LINQ.
var recipients = (from recipient in recipientList
select recipient).Distinct();
My initial thought was to use lambdaj (link text), but it doesn’t appear to support this.
Use an implementation of the interface
Set<T>(class T may need a custom.equals()method, and you may have to implement that.equals()yourself). Typically aHashSetdoes it out of the box : it usesObject.hashCode()andObject.equals()method to compare objects. That should be unique enough for simple objects. If not, you’ll have to implementT.equals()andT.hashCode()accordingly.See Gaurav Saini’s comment below for libraries helping to implement equals and hashcode.