Hi, I'm sabrina ..I have doubts about: How many String this code creates and where (pool Memory or no pool Memory)
String s = new String("Java"); StringBuffer sb = new StringBuffer(); sb.append(s + " " + "is" + " " + "cool");
Nadeem Khan
Ranch Hand
Joined: Nov 27, 2007
Posts: 108
posted
0
Hi, here what i "think":
String s = new String("Java"); ------If this means the same as following: String s = new String();//A String got created in non-pool memory! s = "java"; // A string "java" created in pool memory!
Alex [ February 18, 2008: Message edited by: Alex Belisle Turcot ]
Abhijit Das
Ranch Hand
Joined: Sep 25, 2007
Posts: 156
posted
0
All are saying that the above line creates two objects. One object is "JAVA" referred by 's' and what is the other object and reference variable to refer it. thanks
Abhijit Das
SCJP 5.0 | SCWCD 1.5
Nadeem Khan
Ranch Hand
Joined: Nov 27, 2007
Posts: 108
posted
0
String s = new String("JAVA");
What i inferred from K & B, it creates two objects - "java" in pool memory and another object (new String()) in non-pool.And s points to "java".
Can someone please explain the relation between these two objects getting created here?