for ( Iterator it = list.iterator(); it.hasNext(); ) {
int anInteger = 2;
Object obj = it.next();
// do something with obj and anInteger...
}
}
Solution
Avoid declaring or assigning variables inside a loop that are not dependent on the loop condition.
Where possible, assign them outside the loop to avoid incurring extra costs.
public class ClassA {
public void methodA ( List list ) {
int anInteger = 2;
Object obj; for ( Iterator it = list.iterator(); it.hasNext(); ) {