Program to print the duplicate characters in a string

public static ArrayList<String> checkForDuplicates(String enteredString) {
char[] data = enteredString.toCharArray();
ArrayList<String> duplicateChars = null;
for(int i = 0; i < enteredString.length(); i++) {
for(int j = i+1; j < enteredString.length(); j++) {
if(data[i] == (data[j])) {
System.out.println("Duplicate Characters "+data[j]);
break;
}
}
}
return duplicateChars;
}

public static void main(String[] args) {
checkForDuplicates("madam");
}

Comments

Popular posts from this blog

Android - Using KeyStore to encrypt and decrypt the data

Stack and Queue

Java Reflection API