I'm wondering what the best way of initializing variables so that I don't over use the garbage collector with a for
-loop. Assuming the variable is only used inside the for
-loop. Is it better to declare the variable outside of the for
-loop?
public void foo() {
String tempName;
for (Person person : personList) {
tempName = person.getName();
//Do work with name
}
}
Or inside the for-loop?
public void foo() {
for (Person person : personList) {
String tempName = person.getName();
//Do work with name
}
}