I used to think that String.replace is faster than String.replaceAll because the latter uses Pattern regex and the former does not. But in fact there is no significant differenc
String replace and replace all method there is no diffrence in effiency or time both take n operation to replace the charecter following code may help you how string replace method work in java you can checkout in your eclipse
package com.jav.exec;
public class replace {
static String s1="This the India the india the nation";
public static String replace(String s2,String s3)
{
int counter=0;
int count=s3.length()-1;
int count1=0;
char[] ca1=s1.toCharArray();
char[] ca2=s2.toCharArray();
char[] ca3=s3.toCharArray();
for(int f1=0;f10)
{
ca4[f-counter]=ca1[count2-counter];
counter--;
}
}
count2++;
}
return new String(ca4);
}
public static void main(String[] args)
{
System.out.println(replace("the","mother"));
}
}