I have a list of user inputted names like this
String [] names = new String[x];
Then let's say they entered these names
names = {John, Bill, Sam, John, Joe, Bill};
How do I check for duplicates in this array? and then how do I print out what names are duplicates??
I have this so far, but it is not working
boolean duplicatenames = false;
for (int i = 0; i < names.length; i++) {
for (int j = 0; j < names.length -1; j++) {
if (names[i].equals(names[j])) {
duplicatenames = true;
}
}
}
I think its just checking if there is a duplicate. but how I do I make it print out which names are duplicates?
For example:
"There are duplicate names. These names are: John, Bill"