Saturday, October 11, 2025
HomeLanguagesJavaString Array with Enhanced For Loop in Java

String Array with Enhanced For Loop in Java

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




/*package whatever //do not write package name here */
  
import java.io.*;
  
class GFG {
    public static void main(String[] args)
    {
        String str[] = { "java", "kotlin", "c#", "c" };
  
          // Using Enhanced For Loop
        for (String str1 : str) {
            System.out.println(str1);
        }
    }
}


Output

java
kotlin
c#
c
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32352 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6720 POSTS0 COMMENTS
Nicole Veronica
11885 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6840 POSTS0 COMMENTS
Ted Musemwa
7103 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS