in our project in many places they have used for loops like -
where objList is an List. I havent been able to understand how this is implemented as I somehow prefer using the traditional "for" loop. So can someone please throw some light on this enhanced for loop as they call it.
The above is shorthand for the following:
For arrays it is similar:
Now in your example, objList is probably a List<Integer>, which means that besides this for-each loop, it is also using auto unboxing to convert Integer objects into ints implicitly.
This construct was added to the language to make iterating through collections less uglier or more readable. You can use it to iterate over both a collection and an array(as already demonstrated in earlier posts).
Assuming you know how to use a for loop, if you find this new syntax confusing, try reading it as:
"for each integer i in the objList array or iterable do the following.."