javacodex.com
Java Examples
Java Examples
memu home questions

Java Escape Sequences

\tInsert a tab in the text at this point.
\bInsert a backspace in the text at this point.
\nInsert a newline in the text at this point.
\rInsert a carriage return in the text at this point.
\fInsert 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.

Source: (Escape.java)

public class Escape {
   public static void main(String[] args) {
      System.out.println("Backspace      : " + "ABCDE\bFGHIJ");
      System.out.println("Formfeed       : " + "ABCDE\fFGHIJ");
      System.out.println("Linefeed       : " + "ABCDE\nFGHIJ");
      System.out.println("Single Quote   : " + "ABCDE\'FGHIJ");
      System.out.println("Double Quote   : " + "ABCDE\"FGHIJ");
      System.out.println("Backslash      : " + "ABCDE\\FGHIJ");
      System.out.println("Horizontal Tab : " + "ABCDE\tFGHIJ");
      System.out.println("Carriage Return: " + "ABCDE\rFGHIJ");
   }
}
 

Output:

$ java Escape 
Backspace      : ABCDFGHIJ
Formfeed       : ABCDE
                      FGHIJ
Linefeed       : ABCDE
FGHIJ
Single Quote   : ABCDE'FGHIJ
Double Quote   : ABCDE"FGHIJ
Backslash      : ABCDE\FGHIJ
Horizontal Tab : ABCDE	FGHIJ
FGHIJage Return: ABCDE

Questions answered by this page:

Java Escape Sequences. What are the escape characters in Java? Escape sequence in Java Code Example.

Related Examples:


Contact: javacodex@yahoo.com