
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Display Double and Single Quote in a String in Java
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.
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); } }
Output
Displaying Single Quote: This is Jack's mobile Displaying Double Quotes: "This is it"!
Advertisements