What is an escape character in Java?

Java

1 answer

Answer

1055508

2026-07-15 04:35

+ Follow

The escape character, the back slash: \, is the character that signals the following character is not what it normally means, i.e. as a reserved symbol, or as a new symbol.

The uses of the escape character include:

In Strings when " or ' is a required part of the string

String example1 = "She said,"Hello""; //the escape sequence signifies the " is actually //a " not the end of the String literal.

In Formatting Strings

\n means new line

\t means tab

i.e.

System.out.println("Hello\nHow are you?\tFine thank you.");

// Prints

// Hello

// How are you? [tab] Fine thank you.

And of course the really idiOSyncratic one:

When the back slash is essential to a string, and you don't want it to be a escape character:

\\ means \

i.e.

System.out.println("\");

// Prints \

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.