Monday, January 7, 2013

Different type of ways to iterate a List in java


As List is dynamically growable array. Below are the methods in which you can iterate a List

1. Basic for loop
2. For each loop (introduced from Java 5)
3. While loop
4. Using Iterator
5. Using ListIterator (Unlike Iterator which traverse list in forward direction, ListIterator is used to traverse the list in either direction)

Please see the below code.

No comments:

Post a Comment