There isn't a JDK built in class to do this, but it is part of the Jakarta commons-lang library.
String escaped = StringEscapeUtils.escapeHtml3(stringToEscape);
String escaped = StringEscapeUtils.escapeHtml4(stringToEscape);
Check out the JavaDoc
Adding the dependency is usually as simple as dropping the jar somewhere, and commons-lang has so many useful utilities that it is often worthwhile having it on board.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…