title: What is the recommended way to escape HTML symbols in plain Java?
body: <p>Is there a recommended way to escape <code>&lt;</code>, <code>&gt;</code>, <code>"</code> and <code>&amp;</code> characters when outputting HTML in plain Java code?  (Other than manually doing the following, that is).</p>
  
  <pre><code>String source = "The less than sign (&lt;) and ampersand (&amp;) must be escaped before using them in HTML";
  String escaped = source.replace("&lt;", "&amp;lt;").replace("&amp;", "&amp;amp;"); // ...
  </code></pre>