Most asked top Interview Questions and Answers | Online Test | Mock Test
Education platform for interview prep, online tests, tutorials, and live practice

Build skills with focused learning paths, mock tests, and interview-ready content.

WithoutBook brings subject-wise interview questions, online practice tests, tutorials, and comparison guides into one responsive learning workspace.

Search the library
Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Question: What is String.translateEscapes() in Java 15?
Answer:

Occasionally we get to deal with a string that contains escaped escape sequences, such as the following:

String s = "foo\\nbar\\tbuzz\\\\";System.out.println(s);

The output looks like this:

foo\nbar\tbuzz\\

Sometimes, however, we want to display the evaluated escape sequences: a newline instead of "\n", a tab instead of "\t", and a backslash instead of "\".

Until now, we had to rely on third-party libraries such as Apache Commons Text for this:

System.out.println(StringEscapeUtils.unescapeJava(s));

Starting from Java 15, we can avoid the additional dependency and use the JDK method String.translateEscapes():

System.out.println(s.translateEscapes());

The output now reads:

foobar     buzz

Save For Revision

Bookmark this item, mark it difficult, or place it in a revision set.

Open My Learning Library
Is it helpful? Yes No

Most helpful rated by users:

©2026 WithoutBook