<p>I have an input String say <code>Please go to http://stackoverflow.com</code>. The url part of the String is detected and an anchor <code>&lt;a href=""&gt;&lt;/a&gt;</code> is automatically added by many browser/IDE/applications. So it becomes <code>Please go to &lt;a href='http://stackoverflow.com'&gt;http://stackoverflow.com&lt;/a&gt;</code>.</p>

<p>I need to do the same using Java.</p>

You could do something like this (adjust the regex to suit your needs):
```
```
String originalString = "Please go to http://www.stackoverflow.com";
String newString = originalString.replaceAll("http://.+?(com|net|org)/{0,1}", "<a href=\"$0\">$0</a>");
```
```