Using for each In place of Normal loops in java
for each can be used to display the all the elements of the array.
Syntax :
for(datatype variablename : array)
{
// Do the work with varialble
}
example
public class Main {
public static void main(String[] args) {
int[] intary = { 1,2,3,4};
System.out.println("Elements::");
for(int x :intary)
{
System.out.print(x+" ");
}
}
//output :
//Elements::1 2 3 4
0 Comment(s)