Which loop has better performance? Why?

后端 未结 8 1631
粉色の甜心
粉色の甜心 2020-11-27 11:24
String s = \"\";
for(i=0;i<....){
    s = some Assignment;
}

or

for(i=0;i<..){
    String s = some Assignment;
}
8条回答
  •  醉梦人生
    2020-11-27 12:03

    To add on a bit to @Esteban Araya's answer, they will both require the creation of a new string each time through the loop (as the return value of the some Assignment expression). Those strings need to be garbage collected either way.

提交回复
热议问题