Java Escape Sequences


 

Java Escape Sequences

This tutorial demonstrate the java escape sequence with example.

This tutorial demonstrate the java escape sequence with example.

Description:

In java any character that is preceded by a backslash (\) is known as escape sequence, which has special meaning for the compiler. Following are list of Java escape sequences

Escape Sequence Meaning
\t tab
\n new line
\r carriage return
\' single quote
\" double quote
\\ backslash

Code:

public class ExcapeSeq {
  public static void main(String args[]) {
    System.out.println("Name\tRollNo\tAddress");
    System.out.println("Name\nRollNo\nAddress");
    System.out.println("Name\rRollNo\rAddress");
    System.out.println("Name\'RollNo\'Address");
    System.out.println("Name\"RollNo\"Address");
    System.out.println("Name\\RollNo\\Address");
  }
}

Output:

Download this code

Ads