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 passed stringbuilder's constructor. object in interned pool of strings,
  • "," string object passed split. object in interned pool of strings,
  • an equivalent "521,214" object produced tostring. each call of tostring produces new string object. there no optimization see if in identical string object has been requested before.
  • two string objects "521" , "214" produced split method

it goes without saying string[] array object created hold "521" , "214" objects returned split method.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -