You need a kit. You donβt need a sampling method (what do you think you do) because, as you said, you only have a bunch of objects. And since they use equals and hashCode , the set is exactly what you need.
Of course, a map might also work, because its keys are also a set, but in the end you need to better indicate your requirements, as it seems you are a little confused about your data structure. As I understand it, you really don't need a map.
A hash set implementation will be implemented. Here is what you can do with all of this:
class Foo { final String name; Foo(String name) { this.name = name; } boolean equals(Object obj) { return (obj instanceof Foo) && ((Foo)obj).name.equals(name); } } Set<Foo> fooSet = new HashSet<Foo>(); fooSet.add(new Foo("someFoo")); assert fooSet.contains(new Foo("someFoo"));
source share