Escape Sequence in java

  • A character preceded by a backslash () is known as escape sequence.
  • There are total 8 escape sequences in Java which have special meaning to the compiler.
  • When we use an escape sequence in print statement then the compiler interpret it accordingly.

Escape Sequence

Escape sequences available in java are:
\t - Insert a tab in the text at this point.
\b - Insert a backspace in the text at this point.
\n - Insert a newline in the text at this point.
\r - Insert a carriage return in the text at this point.
\f - Insert a formfeed in the text at this point.
\' - Insert a single quote character in the text at this point.
\" - Insert a double quote character in the text at this point.
\\ - Insert a backslash character in the text at this point.

Let us see the work of following escape sequence-

Escape Sequence Description
t It will insert a tab in the text at this point.
b It will insert a backspace in the text at this point.
f It will insert a formfeed in the text at this point.
n It will insert a newline in the text at this point.
r It will insert a carriage return in the text at this point.
' It will insert a single quote character in the text at this point.
'' It will insert a double quote character in the text at this point.
/ It will insert a backslash character in the text at this point.