Home Tutorial Java Collections Arraylist Java ArrayList listIterator

 
 

Java ArrayList listIterator
Posted on: October 23, 2009 at 12:00 AM
This section demonstrates how to use the method list Iterator() using Java.

  • listIterator() method is used to return a ListIterator reference of the given list.
  • Using this reference all elements of the list can be iterated.
  • It works similar to the iterator() method.


Java Arraylist List Iterator Example
import java.util.*;

public class List1 {

public static void main(String[] args) {
String  ar[]={"india","pakistan","United Kingdom","Japan"};
List list=new ArrayList();
list.add(ar[0]);
list.add(ar[1]);
list.add(ar[2]);
list.add(ar[3]);

ListIterator i=list.listIterator();
while(i.hasNext())
{
System.out.print(i.next()+"   ");
}
}
}
Output
india pakistan United Kingdom Japan 

Related Tags for Java ArrayList listIterator:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.