santhosh.R gowda wrote:How to remove duplicate values in hash map.... as we know we can apply logic and do but i want to use API methods and remove
You cannot have multiple entries with the same
key: calling
put(someKey, someValue) and then
put(someKey, someOtherValue) will overwrite the
someKey - someValue pair.
To check the presence of a
value, you have
Map.containsValue(Object value), but it may not be efficient. You may be better off using 2 Maps, one for
key - value, one for
value - key pairs, or add/remove values to a
(Hash)Set and call
setForValues.contains(value) instead of
map.containsValue(value). You may need to
synchronize these operations to make sure your data is consistent at all times.