Java Unescape HTML to String Example

Java examples to unescape the characters in a String. It unescapes a string containing entity escapes to a string containing the actual Unicode characters corresponding to the escapes.

StringEscapeUtils.unescapeHtml4() [Apache Commons Text]

  • This method takes escaped string as parameter. It can be null.
  • It supports all known HTML 4.0 entities.

To use StringEscapeUtils, import commons-text dependency.


Now use StringEscapeUtils.unescapeHtml4() method.

import org.apache.commons.text.StringEscapeUtils;

public class HTMLEscapeExample 
	public static void main(String[] args) 
		String escapedString = "&lt;java&gt;public static void main(String[] args) { ... }&lt;/java&gt;";
		String unEscapedHTML = StringEscapeUtils.unescapeHtml4(escapedString);


<java>public static void main(String[] args) { ... }</java>

Happy Learning !!


HTML 4.01 Character References

Was this post helpful?

Join 7000+ Fellow Programmers

Subscribe to get new post notifications, industry updates, best practices, and much more. Directly into your inbox, for free.

Leave a Comment


A blog about Java and its related technologies, the best practices, algorithms, interview questions, scripting languages, and Python.