This is the error I get :
Exception in
thread "main" java.lang.Error: Unresolved compilation problem:
ar1 cannot be resolved
Is is required that I need to use Generics here ??? I read an article that said :
"The enhanced for loop makes the explicit use of an iterator unnecessary. Rather than create an Iterator object for the ArrayList and then use the iterator in the for loop, you use the following:
for ( Integer square : squares)
This indicates that the name of the collection is squares. It also indicates that the currently referenced item is of type Integer and is referenced by the variable square.
This code will not compile because there is no way of knowing that the contents of the ArrayList is of type Integer. To fix this, you need to use another feature introduced in J2SE 5.0, namely generics. You need to specify in the declaration and definition of squares that it can only hold elements of type Integer."
Please assist in understanding enhanced for loop when can we use it and when SHOULD WE NOT USE it.