Here's a question.
Which implementation is more efficient ?
HashMap or HashSet.
Now, I know the first difference btwn the two is that HashMap is used for key/value pairs and HashSet is used to just store a set of values. Both are not
thread safe.
The deal is this - We have a pair of key/values BUT due to some reason, the original designer went for a 1 column table that would hold these key/values as "key_value" in the single column.
Now, we have the option of either going for a HashSet to hold this data in memory or a HashMap with the key being the "key_value" and the value being "true".
I prefer the HashSet since all we might have to do is check whether the specified "key_value" exists in the table. That can be easily ( and may I add, lightly ) done by using the contains(Object o) method of the HashSet class. Besides, why unnecessarily have a Map when we don't need one !
Any thoughts on this would be much appreciated.
thanks
Himanshu