public class DuplicateArrayElement {
public static void main(String[] args) {
int[] numArray = {2, 6, 7, 6, 2, 19, 1, 19};
for(int i = 0; i < numArray.length; i++){
for(int j = i + 1; j < numArray.length; j++){
if(numArray[i] == numArray[j]){
System.out.println("Duplicate element found " + numArray[j]);
}
}
}
}
}
public static Set<String> findDuplicates(List<String> listContainingDuplicates) {
final Set<String> setToReturn = new HashSet<String>();
final Set<String> set1 = new HashSet<String>();
for (String yourInt : listContainingDuplicates) {
if (!set1.add(yourInt)) {
setToReturn.add(yourInt);
}
}
return setToReturn;
}
// Uses a set, which does not allow duplicates
for (String name : names)
{
if (set.add(name) == false)
{
// print name your duplicate element
}
}
for (String name : names) {
if (set.add(name) == false) {
// your duplicate element
}
}
System.out.print("Duplicate Characters in above string are: ");
for (int i = 0; i < str.length(); i++) {
for (int j = i + 1; j < str.length(); j++) {
if (carray[i] == carray[j]) {
System.out.print(carray[j] + " ");
break;
}
}
}