<p>Given a word, I've to replace some specific alphabets with some specific letters such as 1 for a, 5 for b etc. I'm using regex for this. I understand that StringBuilder is the best way to deal with this problem as I'm doing a lot of string manipulations. Here is what I'm doing:</p>

<pre><code>String word = "foobooandfoo";
String converted = "";
converted = word.replaceAll("[ao]", "1");
converted = converted.replaceAll("[df]", "2");
converted = converted.replaceAll("[n]", "3");
</code></pre>

<p>My problem is how to rewrite this program using StringBuilder. I tried everything but I can't succeed. Or using String is just fine for this?</p>

I don't know if StringBuilder is the tool for you here. I'd consider looking at
Matcher
which is part of the java regex package and might be faster than your example above
in case you really need the performance
.