Table of Contents

    Escape sequences in Java

    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");