Escape sequences in Java

Rumman Ansari   Software Engineer   2023-12-30 01:04:14   56  Share
Subject Syllabus DetailsSubject Details
☰ TContent
☰Fullscreen

Table of Content:

Escape sequences in Java are special sequences of characters that are used to represent certain characters that are difficult to represent directly in a string. Escape sequences are preceded by a backslash \ and are used to include characters in a string that would otherwise be difficult to include, such as newline characters or quotation marks.

Here are some common escape sequences in Java:

1. \n: Newline


System.out.println("Hello\nWorld");

2. \t: Tab


System.out.println("Hello\tWorld");

3. \b: Backspace


System.out.println("Hello\bWorld");

4. \r: Carriage Return


System.out.println("Hello\rWorld");

5. \: Backslash


System.out.println("This is a backslash: \\");

6. ': Single Quote


System.out.println("This is a single quote: \'");

7. ": Double Quote


System.out.println("This is a double quote: \"");

8. \u####: Unicode Escape


System.out.println("This is a Unicode character: \u03A9");

MCQ Available

There are 10 MCQs available for this topic.

10 MCQ