How do I print escape characters in Java?

Use the method “StringEscapeUtils.escapeJava” in Java lib “org.apache.commons.lang”

String x = "hello\nworld";
System.out.print(StringEscapeUtils.escapeJava(x));

Leave a Comment