views:

511

answers:

4

I'm looking for a structure which hashes keys without requiring a value. When queried, it should return true if the key is found and false otherwise. I'm looking for something similar to Hashtable<MyClass, Boolean> except insertion requires only a key and queries only ever return true or false, never null.

+23  A: 

You need Java's HashSet.

m3rLinEz
+6  A: 

java.util.HashSet? Using contains() for your lookup.

Software Monkey
+2  A: 

See also the static methods Collections#newSetFromMap that creates a set based on the given map implementation. This is eg handy to create a weak hash set.

Adrian
A: 

Java Set is designed to remove duplicates and hopefully the HashMap must be using Java Set internally for managing key as keys can never have duplicates, So you should be considering set for your requirement.

Kalinga