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:

  1. a string corresponds interned "xyz" literal
  2. its copy created new string("xyz")
  3. a string corresponds interned "abc" literal
  4. a string corresponds concatenation "xyz" + "abc"

the real question attributing or of these objects program. 1 can reasonably claim few 2 or many 4 strings 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

Popular posts from this blog

How can we post XML strings along with text strings in iOS -

How to run C# code using mono without Xamarin in Android? -

c# - cefsharp app remember password option -