[java] Quotation marks inside a string

I need some help from you guys. I have a string name = "john"

But I want to save this String name as "john", including ""(quotations)

String name = ""john"";
String name1 = "[john]"

Can some one help me with this.

This question is related to java string

The answer is


You can do this using Escape Sequence.

\"

So you will have to write something like this :

String name = "\"john\"";

You can learn about Escape Sequences from here.


You can add escaped double quotes like this: String name = "\"john\"";


You need to escape the quotation marks:

String name = "\"john\"";