How do i use replace(char, char) to replace all instances of character “b” with nothing.
For example:
Hambbburger to Hamurger
EDIT: Constraint is only JDK 1.4.2, meaning no overloaded version of replace!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s also a replaceAll function that uses strings, note however that it evals them as regexes, but for replacing a single char will do just fine.
Here’s an example:
Note that the
replacedvariable is necessary sincereplaceAlldoesn’t change the string in place but creates a new one with the replacement (Stringis immutable in java).If the character you want to replace has a different meaning in a regex (e.g. the
.char will match any char, not a dot) you’ll need toquotethe first parameter like this: