0
am i doing anything wrong?
string a="somnath"; String b="somnath"; if String was mutable..if i make any change in somnath..both will show the same result as both a and b were referring somnath.. if i m right..why it is not happening in case of StringBuilder.. class StringBuilderMutable { public static void main(String args[]) { StringBuilder r=new StringBuilder("somnath"); StringBuilder r2=new StringBuilder("somnath"); r.replace(1,2,"s"); System.out.print(r+" "+r2); } } why it is not showing same result ?
3 Answers
+ 2
class StringBuilderMutable
{
public static void main(String args[])
{
String a="somnath";
String b="somnath";
a = a.substring(0,1)+'s'+a.substring(2);
System.out.print(a+" "+b);
}
}
I'm not sure what you were trying to do, but this code does the same result as the lower code you had. Hope it helps!
0
thank u..but what am i doing wrong ?,,i want to get the same output
0
r and r2 not point the same reference.