Following piece of code is working only for the first occurence of find string.It is not replacing the second occurence of find string.Could you please help me point out what's worong with this method.
public static
String replace(String source,String find,String replace) {
StringBuffer sb = new StringBuffer(source);
int stringLength = source.length();
int start = 0;
int end = 0;
String result="";
int findLength=find.length();
while((end = source.indexOf(find, start)) != -1) {
start = end + findLength;
sb.replace(end,end+findLength,replace);
}
result = sb.toString();