---
title: "What is advantages of for-each loop"  
description: "What is advantages of for-each loop"  
author: "Jayden Bell"  
published: 2016-07-06  
updated: 2020-09-23  
canonical: https://www.mindstick.com/interview/23024/what-is-advantages-of-for-each-loop  
category: "java"  
tags: ["java i/o"]  
reading_time: 1 minute  

---

# What is advantages of for-each loop

## Advantages of for-each loop

· The for-each construct is very useful if we want to traverse all the elements of the array.

· Specifically, it allows us to iterate over collections and arrays without using iterators or index variables. Although the for statement is quite powerful, it is not optimized for collection iteration.

· The for-each construct can be easily used to dump all the elements of an array on the user console. However, the same thing can be easily achieved by using the toString() method of the Arrays class.

## Answers

### Answer by Jayden Bell

## Advantages of for-each loop

· The for-each construct is very useful if we want to traverse all the elements of the array.

· Specifically, it allows us to iterate over collections and arrays without using iterators or index variables. Although the for statement is quite powerful, it is not optimized for collection iteration.

· The for-each construct can be easily used to dump all the elements of an array on the user console. However, the same thing can be easily achieved by using the toString() method of the Arrays class.


---

Original Source: https://www.mindstick.com/interview/23024/what-is-advantages-of-for-each-loop

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
