Low Orbit Flux Logo 2 F

Java How To Escape Double Quotes In A String

If you want to print a string that includes double quotes in Java you will need to escape those characters. This is extremely easy. Just use a backslash before the double quote character that you want to include in your string.

Here is an example:

System.out.print( "He said it was \"five\" which is what we would expect." );

In the example above the string that is output will have double quotes around the word five.

You can also escape single quotes the same way.