可能重复:
在循环之前或循环中声明变量之间的区别?
String str;
for (int i = 0; i < 10; i++) {
str = "Hello, World"; // Is str created only 1 time?
}
上面和下面有什么区别?如果它们不同,哪一个更好?
for (int i = 0; i < 10; i++) {
String str = "Hello, World"; // Is str created 10 times?
}