Java Escape / Unescape
Escape text into a Java String literal or decode Java escape sequences.
Java Escape and Unescape Online
This Java string escaper converts plain text into the content of a Java String literal and decodes escaped Java strings back into text. Paste a Windows path, a multi-line log message, a JSON payload, or a regular expression and copy a literal you can place between double quotes in .java source, a .properties value, or a unit test.
Java string escaping rules
Inside a double-quoted Java string you have to escape:
"→"and` →\`- line breaks and tabs →
\n,\r,\t, plus\band\f - other control characters →
\u0000-style escapes (Java has no\xescape)
The single quote ' does not need escaping in a String, only in a char literal, but escaping it as ' is legal and harmless. A path such as C:\Program Files\App must become C:\Program Files\App, otherwise the compiler reports "illegal escape character" for \P.
Unicode escapes are processed before compilation
Java is unusual: \uXXXX sequences are replaced by the compiler in a pre-lexing step, anywhere in the source file. That is why "\u0022" does not produce a quote character in a string but ends the literal, and // \u000a inside a comment creates a new line. The Non-ASCII → Escape as \uXXXX option only escapes characters above ASCII, such as ï → \u00EF, which is safe and keeps source files pure ASCII for old build tools with a wrong -encoding.
Text blocks (Java 15)
Java 15 introduced text blocks delimited by """. They keep line breaks and quotes literally, strip common indentation, and add the \s and line-continuation escapes. They are ideal for embedded SQL or JSON; this tool produces classic single-line literals that work on every Java version, including Java 8 and Android.
Unescaping
The Unescape mode reads everything javac accepts: standard escapes, octal \7–\377, \uXXXX (including the rare \uuuu0041 form), and surrogate pairs. Similar tools: C# Escape / Unescape and JavaScript Escape / Unescape.
Frequently Asked Questions
Why does a \u000a in a Java comment break compilation?
The Java compiler translates \uXXXX escapes into characters before it tokenizes the source. \u000a therefore becomes a real line break – even inside a comment or a string – and ends the comment or the string literal early. Use \n for line breaks inside strings; this tool never emits \u000a or \u0022 for that reason.
What escape sequences does Java support?
\b, \t, \n, \f, \r, \", \', \\, octal escapes \0 to \377, \uXXXX Unicode escapes, and since Java 15 \s (a space) and \<line-terminator> for joining lines in text blocks. There is no \v, \a, or \x escape in Java.
Should I use a text block instead?
For multi-line SQL, JSON, or HTML, a Java 15+ text block (""" … """) is often more readable: line breaks and double quotes can be written literally, and only backslashes and triple quotes need attention. For single-line values and older Java versions, a regular escaped string is the only option.
How are emoji escaped?
Java strings are UTF-16, so a character outside the Basic Multilingual Plane is written as two \u escapes (a surrogate pair). The rocket emoji becomes \uD83D\uDE80. The unescaper joins such pairs back into one character.