i use this
org.apache.commons.text.StringEscapeUtils.escapeHtml4("my text % & < >");
add this dependecy
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.8</version>
</dependency>