Replace a substring at a particular position in a string in Java
<p>Following is my string variable :</p>

<pre><code>String str = "Home(om), Home(gia)";
</code></pre>

<p>I want to replace the substring <code>om</code> present between <code>()</code> with <code>tom</code>. </p>

<p>I am able to find the index of <code>()</code> in which <code>om</code> is present, but the following will not work :</p>

<pre><code>int i1 = str.indexOf("(");
int i2 = str.indexOf(")");

str = str.replace(str.substring(i1+1,i2),"tom");
</code></pre>

<p>I require the result as <code>Home(tom), Home(gia)</code>.</p>

<p>How to do this?</p>