Question :
public class StringTest
{
public static void main(String
args[])
{
String s = "sachin";
s.concat("tendulkar");
System.out.println(s);
}
}
Output:
sachinBecause String is immutable in Java.
Question :
public class StringTest
{
public static void main(String
args[])
{
String s = "sachin";
s=s.concat("tendulkar");
System.out.println(s);
}
}
Output:
sachintendulkarHere a new string "sachintendulkar" is created and 's' is made as a reference to this new string.
String object "sachin" still exist in the string constant pool.
0 comments:
Post a Comment