Issue
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 transform string to Bttl f th V wls:Hw vs Grzny
.
Found this question in the book href="https://rads.stackoverflow.com/amzn/click/com/0471383562" rel="noreferrer" rel="nofollow noreferrer">Programming Interviews Exposed. This was explained in C, however I'm interested in Java.
Solution
One simple way to do this is to use a regular expression:
"Battle of the Vowels:Hawaii vs Gronzy".replaceAll("[aeiou]","")
Some Java Class Library API documentation:
String.replaceAll: http://download.oracle.com/javase/1.5.0/docs/api/java/lang/String.html#replaceAll(java.lang.String,%20java.lang.String)
Patterns and regular expressions: http://download.oracle.com/javase/1.5.0/docs/api/java/util/regex/Pattern.html#sum
Answered By - Mike Tunnicliffe
Answer Checked By - Senaida (JavaFixing Volunteer)