As of Java 5, the enhanced for loop was introduced.This is mainly used for arrays.
The syntax of enhanced for loop is :-
for(declaration : expression)
{
// Statement
}
Declaration : -
The newly declared block variable , Which is of a type compatible with the elements of the array we are accessing . The variable will be available within the for block and its value would be the same as the current array element .
Expression :-
This evaluates to the array we need to loop through. The expression can be an array variable or method call that returns an array .
No comments:
Post a Comment