Is declaring a variable inside a loop is good or declaring on the fly optimal in Java.Also is there any performance cost involved while declaring inside the loop?
eg
The most optimal way to traverse a list is to use an Iterator.
for (Iterator iter=list.iterator(); iter.hasNext();) { System.out.println(iter.next()); }