Good Idea, William. Timely reminder for me, since i used to do this earlier but dropped.
Prateek, Set ( which internally uses a map) compares hashvalue && (reference equality || object equality) before saving a new value.
Look up rt.jar like William suggested using a Java Decompiler, for more details.
krishna kanth wrote:However, just verified that AbstractSet did not implement add method.
Hmmm. Probably because, like most 'mod' operations, it's optional.
I have to admit being quite surprised (although I'm sure you're right), but it's probably to ensure structural independence. And my general point was that "duplicate" maintenance is far more likely to be based around contains() than add().