Skip to main content

Java Escape — Escape & Unescape Java Strings Online

Free online Java string escape tool: turn any text into a valid Java string literal — escaping quotes, backslashes, newlines, tabs and Unicode per JLS §3.10.6 — or unescape Java strings back to readable text. Octal escapes, surrogate pairs and multi-u Unicode escapes supported. 100% client-side, nothing is uploaded.

Java string escape / unescape

Paste text on the left, get a compilable Java literal on the right. Switch to Unescape to decode \n, \t, \", \uXXXX and octal escapes back to plain text.

Honest scope note: escape output follows JLS §3.10.6 exactly (short escapes where they exist, \u00XX for other controls, optional \uXXXX for non-ASCII). Unescape decodes short escapes, \s (Java 15+), Unicode escapes with one or more us, and octal escapes \0–\377. Undefined escapes like \q are passed through unchanged and counted — real javac would reject them.

How to escape a Java string

  1. Paste your raw text into the input box (quotes, backslashes, line breaks and Unicode are all fine).
  2. Keep Escape mode to produce a valid Java string literal, or switch to Unescape to decode an escaped literal back to text.
  3. Tune the options: quote style, single-quote escaping, non-ASCII → \uXXXX, or quote stripping.
  4. Copy the result or download it — conversion is instant and the stats bar shows exactly what changed.

Java escape sequences reference (JLS §3.10.6)

Every escape sequence the Java Language Specification allows inside character and string literals.

EscapeCharacterUnicodeNotes
\bBackspaceU+0008
\sSpaceU+0020Since Java 15 (text blocks)
\tHorizontal tabU+0009
\nLine feedU+000ARequired — raw newlines are illegal in literals
\fForm feedU+000C
\rCarriage returnU+000D
\"Double quoteU+0022Required inside "..." literals
\'Single quoteU+0027Required only in char literals; legal in strings
\\BackslashU+005CAlways required
\uXXXXAny BMP characterU+0000–U+FFFFOne or more us allowed: \uuuu0041 = A
\0–\377Octal escapeU+0000–U+00FF1–3 octal digits, e.g. \101 = A

Quick examples

He said "Halo!" → "He said \"Halo!\""
café → "caf\u00e9"  ·  \101 → A (octal)  ·  \u0041 → A (unicode)

Frequently asked questions

What does a Java escape tool do?

It converts raw text into a valid Java string literal by escaping characters the Java compiler treats specially. For example, He said "Halo!" becomes "He said \"Halo!\"" — the inner quotes are prefixed with a backslash so javac reads them as quote characters instead of the end of the literal. This is essential when pasting text with quotes, backslashes, or line breaks into Java source code.

Which escape sequences are valid in Java string literals?

JLS §3.10.6 defines: \b (backspace), \t (tab), \n (line feed), \f (form feed), \r (carriage return), \" (double quote), ' (single quote), \ (backslash), \s (space, Java 15+), Unicode escapes \uXXXX, and octal escapes \0 to \377. Anything else after a backslash — like \q — is a compile-time error in real Java code.

How do I escape double quotes inside a Java string?

Prefix each double quote with a backslash: \". For example, She said "yes". becomes "She said \"yes\".". Single quotes do not need escaping inside a double-quoted string (it's is legal as-is), though ' is also accepted by the compiler. Enable the "Escape single quotes" option here if your serializer or style guide wants them escaped anyway.

What is \uXXXX and when should I use it?

It is a Java Unicode escape: four hex digits naming the character, e.g. café becomes "caf\u00e9". Use it for any non-ASCII character when you cannot guarantee the source file encoding — a literal é compiles fine in UTF-8 but breaks in Latin-1. Astral characters (emoji) become a surrogate pair: 😀 becomes "\ud83d\ude00". Hex digits may be upper- or lowercase; this tool emits lowercase.

How does Unescape mode handle octal escapes like \101?

It follows JLS octal rules: \0 to \377, where \101 decodes to A, \0 to the NUL character, and \377 to ÿ. Most online tools ignore octal escapes; this one decodes them, plus multi-u Unicode escapes (\uuuu0042 → B) and \s (Java 15+). Sequences Java does not define, such as \q, are passed through unchanged — strict javac would reject them, so they are counted as "unknown" in the stats bar.

Why does javac say "illegal line end in string literal"?

Java string literals may not contain a raw line break — every newline must be written as \n (and carriage returns as \r). Pasting multi-line text directly between quotes triggers this error. Paste the text into this tool's Escape mode and it converts each line break to \n automatically.

Is my text uploaded to a server?

No. Escaping and unescaping run entirely in your browser with zero network requests — your text never leaves the page. You can verify this in your browser developer tools: this page makes no fetch or XHR calls.

How is Java escaping different from JSON escaping?

JSON (RFC 8259) allows only \", \\, \/, \b, \f, \n, \r, \t and \uXXXX — it has no ', no octal escapes, and no \s. Java additionally supports ' (single quote), octal escapes \0–\377, and \s (Java 15+). A Java-escaped string containing ' or \101 is not valid JSON, so use each escaper for its own language.

Free tool by NRTechStudio