Originally posted by karthik vijayarajan:
As i understand, the map implementations by itself do not prevent duplicates. You may also want to try out one of the set implementations.
Maps do, indeed, by definition, prevent duplicate keys. They don't prevent duplicate
values. If you're using a Set, then there
are no values, of course, only keys, so it's no different.
Note that all the Set implementations that are part of the standard API are actually implemented in terms of a Map; it's just a Map that stores a key against itself.