enter String inside a another string quotes

I need to use a string something like this

String x = "return "My name is X" ";

We can see the issue is first and second quotes wll be treated as a String in itself , but actually first and last quote should form 1 string , while 2nd and 3rd quotes should form another string inside that.

Any solution for this?

Jon Skeet
people
quotationmark

You just need to escape the double-quote within the string literal:

String x = "return \"My name is X\" ";

There are other characters which can be escaped like this too - for example:

String tab = "before\tafter";

(That's "before", then a tab, then "after".)

See the JLS section 3.10.6 for all escape sequences.

people

See more on this question at Stackoverflow