java - How many strings are produced in a .toString.split(","); call? -
suppose have following code:
stringbuilder sb = new stringbuilder("521,214"); string[] result = sb.tostring().split(","); my question is: tostring().split(",") generate 2 strings or 3 strings? know result string array have 2 strings - tostring() call generate string - isn't returned?
basically, i'm trying limit number of strings created performance purposes , want know if tostring() call brings total number of strings created 3?
there 5 string object created in total these 2 lines:
"521,214"object passedstringbuilder's constructor. object in interned pool of strings,","string object passedsplit. object in interned pool of strings,- an equivalent
"521,214"object producedtostring. each call oftostringproduces newstringobject. there no optimization see if in identical string object has been requested before. - two
stringobjects"521","214"producedsplitmethod
it goes without saying string[] array object created hold "521" , "214" objects returned split method.
Comments
Post a Comment