how can I replace a specific word from user input and display it as an asterisk. This is my code.
String[] filteredWords = ["apple", "banana", "orange"];
private String convertWord(String input) {
StringBuilder asterisk = new StringBuilder();
for (String filter: filteredWords) {
if (input.toLowerCase().contains(filter)) {
for (int i = 0; i < filter.length(); i++) {
asterisk.append("*");
}
input = input.replace(filter, asterisk.toString());
}
}
return input;
}
for example the user input or type "This is apple and not orange", the expected output would be "This is ***** and not ******".
but my problem here is when the user type (with a character casing) "This is Apple and not oRaNGE" or "This is aPpLe and not Orange" the output is not changing. The word apple and orange are not being replace with an asterisk.
any help is appreciated. Thank you!