Iterating Collections and Arrays

Hello Friends,

This is one of tutorials regarding the iterating Collections and Arrays. There are two ways of iterating the elements in the Collections or Arrays. One of the method is using the Iterator and another is using the advanced for loop or foreach statement.  Iterator are used instead of Enumeration in Java and are used to iterate the elements in particular collection. Iterator is mostly used with the collection framework. Whereas advance for loop, introduced in JDK ver. 5, is used with collections and Arrays. It is the enhancement in the for statements, it does not include any type of counters as that of simple for loop.

However, the for-each statement cannot be used in all circumstances. Iterator cannot be used directly with array, so we have to convert the array into a collection, then use the iterator on it for iteration .Following is the code that shows the use of both in Collections and Arrays.

Hope this will help you.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.