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+ Awesome Developers

Get the latest updates from industry, awesome resources, blog updates and much more.

* We do not spam !!

Leave a Comment


A blog about Java and related technologies, the best practices, algorithms, and interview questions.