java - How much string objects are created (String.format())? -
after dispute colleague couldn't find solution. question
for(int = 0; < 2; i++) { string.format("variable = %d", i); }
how variables created during running code? have opinion, here can created 4 variables:
- "variable = %d",
- "variable = %d" - on both cycle steps created object formatting
- "variable = 0",
- "variable = 1" - resulted strings.
am right?
"variable = %d"
string literal, put in string pool , not created twice. hence, you'll have total of 3 strings: "variable = %d"
, "variable = 0"
, "variable = 1"
.
Comments
Post a Comment