I understand in a hashmap you have a KEY and VALUE.
What's the most efficient way to make sure none of your values are the same as each other? That is, check to make sure you have no duplicate values?
Thanks!
You could either call the containsValue method to see if a value is in the map already before adding new elements, or write your own subclass of HashMap that overrides the put and putAll methods to do that check automatically.
so what you want is a 1-to-1 cardinality?If you look here, you find that Map models the mathematical concept of a function. What you now want is called an injection (or an injective function).