Line breaks and tabs
Description
\n starts a new line and \t inserts a tab.
Explanation
They are interpreted inside a quoted Java string.
Example
System.out.println("Name\tScore\nAditi\t92");← Chapter 3 — Strings, Escapes & Math
mixed
Escape sequences represent characters that are hard to type directly inside a String. They begin with a backslash.
Use escapes to add new lines, tabs, quotation marks, or a literal backslash. This is especially useful for formatted messages and file paths.
\n starts a new line and \t inserts a tab.
They are interpreted inside a quoted Java string.
System.out.println("Name\tScore\nAditi\t92");Escape quote and backslash characters.
A backslash changes the meaning of the character after it.
String quote = "She said \"Great!\"";Do not confuse the two-character text \n with an actual line break. Java interprets it as a line break only inside a String or character literal.
public class EscapeDemo {
public static void main(String[] args) {
System.out.println("Student\tGrade");
System.out.println("Aditi\tA");
}
}