Thursday, June 11, 2026
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

1 COMMENT

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6896 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS