• Register
100 points

We can also print the Java array using for-each loop. The Java for-each loop prints the array elements one by one. It holds an array element in a variable, then executes the body of the loop.

The syntax of the for-each loop is given below:

for(data_type variable:array){  
//body of the loop  


Let us see the example of print the elements of Java array using the for-each loop.

//Java Program to print the array elements using for-each loop  
class Testarray1{  
public static void main(String args[]){  
int arr[]={33,3,4,5};  
//printing array using for-each loop  
for(int i:arr)  

The output will Be:


More Posts

Java- What are arrays and How do we use them muliemes - May 18
Difference between For Each and For Loop sakshi - Jun 1
How to print multidimensional array in PHP using for loop Tushar Shuvro - May 19, 2020
Difference between For and Foreach in Java sakshi - Jul 1
How to print an array in java. Hasnain_khan - Oct 9, 2020
Difference between for and while loop Sanjana Sagar - May 29
How to Return an Array from a Method muliemes - May 18
Shuffling array in java Davud - May 19
Declaration, Instantiation and Initialization of Java Array muliemes - May 18
Solution to error: 'for' loop initial declarations are only allowed in C99 mode amna - Oct 3, 2020