·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.
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
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.