Advertisement
String s1 = "Sky"; // Statement1
String s2 = "Blue" // Statement2
s1 = s1 + s2; // Statement3
Advertisement
//String Immutability
public class String1
{
public static void main(String[] ar)
{
//String object created on String constant pool heap memory, without using new keyword
String s1= "Sky";
String s2= "Blue"
s1= s1+s2; //Statement 1
System.out.println("s1 points to " + s1);
System.out.println("s2 points to " + s2);
//String objects created on normal heap memory, using new keyword
String s3 = new String("New");
String s4 = new String("York");
s3= s3+s4; //Statement 2
System.out.println("s3 points to " + s3);
System.out.println("s4 points to " + s4);
}
}
s1 points to SkyBlue
s2 points to Blue
s3 points to NewYork
s4 points to York
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement