String s = new String ("abc");
In this case, because we used the new keyword, Java will create a new String object in normal (nonpool) memory, and s will refer to it. In addition, the literal "abc" will be placed in the pool.
SCJP with 98% by...
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankur kothari wrote:does this mean that
String s=new String("abc"); and
String s1=new String("abc") actually create 3 objects?
if yes then we are clear on this.....
SCJP 6
Ankur kothari wrote:if yes then we are clear on this.....
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankur kothari wrote:we refers to both of us....
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
SCJP 6
Ankur kothari wrote:you will see....
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankur kothari wrote:Ankit please explain me this....am sorry for above.
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Oops, I guess i had typed it wrong; instead of String literal pool, i written string buffer.Punit Singh wrote:Even Soumil Shah is also not clear, see his answer, he is creating an object on the buffer pool. While objects are always created on the heap.
Soumil Shah wrote:
Oops, I guess i had typed it wrong; instead of String literal pool, i written string buffer.Punit Singh wrote:Even Soumil Shah is also not clear, see his answer, he is creating an object on the buffer pool. While objects are always created on the heap.
SCJP 6