·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.
Liked By
Write Answer
What is advantages of for-each loop
Join MindStick Community
You have need login or register for voting of answers or question.
Jayden Bell
06-Jul-2016Advantages 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.