Answers for "how to check if an array has duplicate values"

1

javascript check if array has duplicates

function hasDuplicates(array) {
    return (new Set(array)).size !== array.length;
}
Posted by: Guest on July-28-2020
1

java find duplicates in array

// Uses a set, which does not allow duplicates 

for (String name : names) 
{
     if (set.add(name) == false) 
     {
        // print name your duplicate element
     }
}
Posted by: Guest on May-09-2020

Code answers related to "how to check if an array has duplicate values"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language