1import java.util.ArrayList;
2import java.util.ListIterator;
3public class ArrayListListIteratorMethodExample
4{
5 public static void main(String[] args)
6 {
7 ArrayList<String> al = new ArrayList<String>();
8 al.add("plum");
9 al.add("apple");
10 al.add("orange");
11 al.add("mango");
12 al.add("pineapple");
13 System.out.println(al);
14 ListIterator<String> iterate = al.listIterator(1);
15 while(iterate.hasNext())
16 {
17 String str = iterate.next();
18 System.out.println(str);
19 }
20 }
21}
1example on listIterator() method IndexOutOfBoundsException
2import java.util.ArrayList;
3import java.util.ListIterator;
4public class ArrayListListIteratorMethodExample
5{
6 public static void main(String[] args)
7 {
8 ArrayList<String> al = new ArrayList<String>();
9 al.add("plum");
10 al.add("apple");
11 al.add("orange");
12 al.add("mango");
13 al.add("pineapple");
14 System.out.println(al);
15 ListIterator<String> iterate = al.listIterator(5);
16 System.out.println(iterate.hasNext());
17 iterate = al.listIterator(6);
18 }
19}