Explain the Escape Sequences in Java.
Advertisements
Question
Explain the Escape Sequences in Java.
Advertisements
Solution
In Java, Escape Sequences are special character combinations used to represent characters that cannot be directly typed or displayed in a string. An escape sequence begins with a backslash (\) followed by a character. These sequences are mainly used to format text and control the output of a program.
The commonly used escape sequences in Java are as follows:
|
Escape Sequence |
Description |
|---|---|
|
|
It is used to move the cursor to a new line. |
|
|
It is used to insert a horizontal tab space. |
|
|
It represents a backspace character. |
|
|
It is used to move the cursor to the beginning of the current line. |
|
|
It represents a form feed character. |
|
|
It is used to represent a single quotation mark. |
|
|
It is used to represent a double quotation mark. |
|
|
It is used to represent a backslash character. |
Example:
System.out.println("Hello\nJava");
Output:
Hello
Java
