Home > DeveloperSection > Interviews > What is advantages of for-each loop

Posted on    July-06-2016 3:52 AM

 Java Java I/O 
 1 Answer(s)
  592  View(s)
Rate this:

Jayden Bell
Jayden Bell

Total Post:13

Posted on    July-06-2016 3:52 AM

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.

Modified On Jul-06-2016 03:53:57 AM

Don't want to miss updates? Please click the below button!

Follow MindStick