Counting String objects created by Java code -
how many string objects created following code?
string x = new string("xyz"); string y = "abc"; x = x + y;
i have visited many websites line of code creates 3 objects , creates 4. wanted know how many objects created after line of code executed.
by end of run there 4 string
objects:
- a
string
corresponds interned"xyz"
literal - its copy created
new string("xyz")
- a
string
corresponds interned"abc"
literal - a
string
corresponds concatenation"xyz" + "abc"
the real question attributing or of these objects program. 1 can reasonably claim few 2 or many 4 string
s created code. though there 4 string
objects in total, objects 1 , 3 may not created code, because in constant pool, created outside code's direct control.
Comments
Post a Comment