I want to display the values in a HashMap. A HashMap may have duplicate values (but not duplicate keys), but I want to display a value only once. 
So I should find whether the Map has duplicate values. I know we can iterate over the Map and use the return boolean of map.containsValue(value). I want to know whether any method exists to find duplicate values in map or we should I write code myself?  
Try out this code
private boolean hasDuplicates(Map<Integer, List<String>> datamap){
boolean status = false;
    Set valueset=new HashSet(datamap.values());
    if(datamap.values().size()!=valueset.size()){
    status=true;
    }
    else{
    status = false;
    }
    return status;
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With