String Array with Enhanced For Loop in Java
Last Updated :
08 Apr, 2023
Enhanced for loop(for-each loop) was introduced in java version 1.5 and it is also a control flow statement that iterates a part of the program multiple times. This for-loop provides another way for traversing the array or collections and hence it is mainly used for traversing arrays or collections. This loop also makes the code more readable and reduces the chance of bugs in the code.
Syntax:
for(data-type variable : array | collection)
{
// Code to be executed
}
In this article, we will see how to get array Strings using Enhanced For Loop.
Implementation
Java
import java.io.*;
class GFG {
public static void main(String[] args)
{
String str[] = { "java" , "kotlin" , "c#" , "c" };
for (String str1 : str) {
System.out.println(str1);
}
}
}
|
Share your thoughts in the comments
Please Login to comment...