title: Replace Special characters with Character references in string using java
body: <p>I have a String with special characters which I want to be replaced by corresponding reference.</p>
  
  <p>For example</p>
  
  <pre><code>InputString -&gt; Hi &lt;Nishanth&gt; How &amp;are you !
  OutputString -&gt; Hi &amp;ltNishanth&amp;gt How &amp;ampare you &amp;excl
  </code></pre>
  
  <p>I tried using concept of replace. But I couldn't achieve the desired result ..
  I want a function which would do it for me in Java.</p>