Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (830 points)

I can use this:

String str = "TextX Xto modifyX";
str = str.replace('X','');//that does not work because there is no such character ''

Is there a way to remove all occurrences of character X from a String in Java?

I tried this and is not what I want: str.replace('X',' '); //replace with space

1 Answer

0 votes
by (13.2k points)

    You can use string as an argument rather than a char ,

                      Therefore, the code becomes

                          str = str.replace("X", "");

         Or you can also use unicode

                          str = str.replace("\uffff", "");

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...