I have a string \"Notes\":[\"
How to initialize \"Notes\":[\" to a string using JAVA?
I tried String subString1 = "\"Notes\":[";
but getting only "Notes":[
I have a string \"Notes\":[\"
How to initialize \"Notes\":[\" to a string using JAVA?
I tried String subString1 = "\"Notes\":[";
but getting only "Notes":[
The initialisation String subString1 = "\"Notes\":[";
is correct as it initializes it with "Notes":[
.
If you want to keep the \
, you'll have to add an extra \
:
String subString1 = "\\\"Notes\\\":[";
If you want to have an extra double quote at the end, you can also add it:
String subString1 = "\\\"Notes\\\":[\"";
This is because \"
will result in "
and \\
will result in \
So, \\\"
will result in \"
.
Do it as follows:
public class Main {
public static void main(String[] args) {
String subString1 = "\\\"Notes\\\":[\\\"";
System.out.println(subString1);
}
}
Output:
\"Notes\":[\"
You need to escape \
as well by using another \