How do you replace double quotes with a blank space in Java?

angad Soni picture angad Soni · Mar 2, 2010 · Viewed 137.1k times · Source

For example:

"I don't like these "double" quotes"

and I want the output to be

I don't like these double quotes

Answer

cletus picture cletus · Mar 2, 2010

Use String#replace().

To replace them with spaces (as per your question title):

System.out.println("I don't like these \"double\" quotes".replace("\"", " "));

The above can also be done with characters:

System.out.println("I don't like these \"double\" quotes".replace('"', ' '));

To remove them (as per your example):

System.out.println("I don't like these \"double\" quotes".replace("\"", ""));