String is not a mutable object.
String s ="a";
s = s+"b";
when u compile the code above, "+" operator will be changed by your compiler;
String s=new String("a");
StringBuffer sbimp = new StringBuffer(s);
sbims.append("b");
s=sbims.toString();
so it's not recomended to use "+" operator so much.
for ex:
code1
------------------------------
String a="";
for(int i=0;i<20000;i++){
a=a+i;
}
code2
-------------------------------------------
String a="";
StringBuffer sb="";
for(int i=0;i<20000;i++){
sb.append(i);
}
code2 will be 1000 times faster cause first code means.
String a="";
for(int i=0;i<20000;i++){
String a=new String("a");
StringBuffer sbimp = new StringBuffer(a);
sbims.append("b");
a=sbims.toString();
}