What is Escape sequence?
In Java, an escape sequence is a combination of characters that represents a special character when used within a string. It begins with a backslash (‘\’) and is followed by one or more characters. Escape sequences are used to include special characters in strings, such as newline characters (\n), tab characters (\t), or quotation marks (\”). They enable the representation of characters that would otherwise be difficult or impossible to include directly in a string.
List of Escape Sequences:
1. \n : Inserts a newline:
Example:
Output:
“java
is
an
interesting
language”
Explanation:
2. \t : Inserts a tab:
Example:
Output:
Hi
there
3. \” : Inserts a double quote:
Example:
Output:
“hello world”
Explanation:
4. \’ : Inserts a single quote:
Example:
Output:
‘Programming’ is fun
Explanation:
5. \\: Inserts a backslash:
Example:
Output:
Programming\fun
Explanation:
6.\r: carriage return:
Example:
Output:
Programming
fun
7. \f: form feed:
Example:
Output:
Good Morning Mariya! How are you?
8. \b: Inserts a backspace:
Example:
Output:
Good Morning Mariya!
Implement of Escape Sequence:
Output:
Hello!
welcome to programming world
‘Programming’ is fun
\”Java”is on of the best programming language.\
Visited 1 times, 1 visit(s) today