Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.
In Java, for-each loop traverses an array or collection of elements one by one. In place of declaring and initializing a loop counter variable, you declare a variable of the same type as the array's base type, followed by a colon and the array name.
Syntax:
for (type var : array)
{
//statements to be executed
}
Let’s look at the following Java program using a for-each loop that prints the elements of an Array.
class Example {
public static void main(String[] args) {
int[] num = {1, 3, 5, 7};
// for each loop
for (int num1: num) {
System.out.println(num1);
}
}
}
Test your websites, web-apps, or mobile apps seamlessly with LambdaTest.
Start Free TestingEarn resume-worthy Selenium certifications that help you land a top job.
Learn MoreTest orchestration and execution cloud of 3000+ browsers and OS
24/7 support
Enterprise grade security
Fastest test execution cloud