enhanced for-loop,
for (String element : array) { System.out.println("Element: " + element);}
enhanced for-loop,
for (String element : array) { System.out.println("Element: " + element);}
Enhanced For Loop
As of Java 5, the enhanced for loop was introduced. This is mainly used to traverse collection of elements including arrays.
Syntax :
for(declaration : expression) {
// Statements
}
Declaration − The newly declared block variable, is of a type compatible with the elements of the array you 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 you need to loop through. The expression can be an array variable or method call that returns an array.
enhanced for-loop,
for (String element : array) { System.out.println("Element: " + element);}
enhanced for-loop,
for (int i=0; i < array.length; i++) { System.out.println("Element: " + array[i]);}
Enhanced For Loop
As of Java 5, the enhanced for loop was introduced. This is mainly used to traverse collection of elements including arrays.
Syntax :
for(declaration : expression) {
// Statements
}
Declaration − The newly declared block variable, is of a type compatible with the elements of the array you 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 you need to loop through. The expression can be an array variable or method call that returns an array.
enhanced for-loop,
for (int i=0; i < array.length; i++) { System.out.println("Element: " + array[i]);}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us