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

Leave a Reply

Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.

Our Blogs

REST API Tutorial