check duplicate key and value in hashmap
i was wondering how you would check for a duplicate item that has both the same key and value.
ie, if you do like
is there a way to check a string that has exactly that key?
if i map another "David" with 555, that's totally fine.
but im having trouble trying to figure out a way to check if there is another item that has "David" with 123.
any pseudocode would be great = )
thank you = )
Re: check duplicate key and value in hashmap
By default, keys are unique in a Map (in other words there aren't duplicate keys). If you are trying to look for duplicate values, you could a) iterate over the Map to look for duplicates or b) stick the values from the first Map (call it mapA) in another map (call it mapB) as keys, valued to a list of the keys from mapA - basically reverse the Map. You can then retrieve them and see if there are duplicates based upon the List size.