For example, given a string of Battle of the Vowels:Hawaii vs Gronzy
when we specify the characters to be removed as aeiou
, the function should transfo
public class RemoveChars {
char[] replaceChar = {'a','e','i','o','u'};
public static void main(String[] args) {
String src = "Battle of the Vowels:Hawaii vs Gronzy";
System.out.println(new RemoveChars().removeChar(src));
}
public String removeChar(String src){
char[] srcArr = src.toCharArray();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < srcArr.length; i++) {
char foundChar = isFound(srcArr[i]);
if(foundChar!='\0')
sb.append(foundChar);
}
return sb.toString();
}
public char isFound(char src){
for (int i = 0; i < replaceChar.length; i++) {
if(src==replaceChar[i]){
return '\0';
}
}
return src;
}
}