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 Programming Interviews Exposed. This was explained in C, however I'm interested in Java.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With