The following are our strings with single and double quote.
String str1 = "This is Jack's mobile"; String str2 = "\"This is it\"!";
Above, for single quote, we have to mention it normally like.
This is Jack's mobile
However, for double quotes, use the following and add a slash in the beginning as well as at the end.
String str2 = "\"This is it\"!";
The following is an example.
public class Demo { public static void main(String[] args) { String str1 = "This is Jack's mobile"; String str2 = "\"This is it\"!"; System.out.println("Displaying Single Quote: "+str1); System.out.println("Displaying Double Quotes: "+str2); } }
Displaying Single Quote: This is Jack's mobile Displaying Double Quotes: "This is it"!