💡 Outline
You can print double quotes in java by escape double quotes using backslash character(\
).
1234 System.out.println("\"Java2blog is java blog\"");// output: "Java2blog is java blog"
When you print on console using System.out.println, you use double quotes and whatever value inside double quotes is printed. But what if you want to actually print double quotes on console.
In this tutorial, we will see different method to print quotation marks in java.
Table of Contents
Print double quotes in java using backslash character
You can use backslash character(\
) to escape the double quotes and it will be printed on the console.
1 2 3 4 5 6 7 8 9 10 |
package org.arpit.java2blog; public class PrintQuotationMarksMain { public static void main(String[] args) { System.out.println("\"Hello world from java2blog\""); } } |
Output:
Print double quotes in java using unicode character
You can use unicode character of double quotes and append it to String to print quotation marks in java.
unicode character of double quotes is \u0022
, so we will append this unicode character in the string.
Example
1 2 3 4 5 6 7 8 9 10 |
package org.arpit.java2blog.entry; public class PrintQuotationMarksMain { public static void main(String[] args) { System.out.println('\u0022'+"Hello world from java2blog"+'\u0022'); } } |
Output:
As you can see, when we printed the string, unicode characters converted into double quotes. That’s how you can print quotation marks in java.
Print double quotes in java by appending double quote character
You can put double quote in single quotes to convert it to character and append to the string to print quotation marks in java.
Example
1 2 3 4 5 6 7 8 9 10 |
package org.arpit.java2blog.entry; public class PrintQuotationMarksMain { public static void main(String[] args) { System.out.println('"'+"Hello world from java2blog"+'"'); } } |
Output:
That’s all about how to print double quotes in java.