List listIterator() Method in Java with Examples Last Updated : 02 Jan, 2019 Comments Improve Suggest changes Like Article Like Report This method returns a list iterator over the elements in the mentioned list (in proper sequence), starting at the specified position in the list. Syntax: ListIterator listIterator(int index) Parameters: This method has only argument, i.e, index - index of the first element to be returned from the list iterator (by a call to next). Returns: This method returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list. Exception: This method throws an exception IndexOutOfBoundsException - if the index is out of range (index size()) Below programs show the implementation of this method. Program 1: Java // Java program to demonstrate // listIterator() method // for List interface import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { try { // Creating object of List<Integer> List<Integer> arrlist = new ArrayList<>(); // adding element to arrlist arrlist.add(1); arrlist.add(3); arrlist.add(6); arrlist.add(9); // print arrlist System.out.println("ArrayList: " + arrlist); // Creating object of ListIterator<String> // using listIterator() method ListIterator<Integer> iterator = arrlist.listIterator(); // Printing the iterated value System.out.println("\nUsing ListIterator:\n"); while (iterator.hasNext()) { System.out.println("Value is : " + iterator.next()); } } catch (NullPointerException e) { System.out.println("Exception thrown : " + e); } } } Output: ArrayList: [1, 3, 6, 9] Using ListIterator: Value is : 1 Value is : 3 Value is : 6 Value is : 9 Program 2: Below is the code to show implementation of list.subList() using Linkedlist. Java // Java program to demonstrate // listIterator() method // for List interface import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { try { // Creating object of List<Integer> List<String> arrlist = new ArrayList<String>(); // adding element to arrlist arrlist.add("A"); arrlist.add("B"); arrlist.add("C"); arrlist.add("D"); // print arrlist System.out.println("ArrayList: " + arrlist); // Creating object of ListIterator<String> // using listIterator() method ListIterator<String> iterator = arrlist.listIterator(); // Printing the iterated value System.out.println("\nUsing ListIterator:\n"); while (iterator.hasNext()) { System.out.println("Value is : " + iterator.next()); } } catch (NullPointerException e) { System.out.println("Exception thrown : " + e); } } } Output: ArrayList: [A, B, C, D] Using ListIterator: Value is : A Value is : B Value is : C Value is : D Reference: Oracle Docs Comment More infoAdvertise with us Next Article List listIterator() Method in Java with Examples B barykrg Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions java-list +2 More Practice Tags : JavaJava-CollectionsMisc Similar Reads Vector listIterator() method in Java with Examples java.util.Vector.listIterator() This method returns a list iterator over the elements of a Vector object in proper sequence. It is bidirectional, so both forward and backward traversal is possible, using next() and previous() respectively. The iterator thus returned is fail-fast. This means that str 3 min read Stack listIterator() method in Java with Example The listIterator() method of Java.util.Stack class is used to return a list iterator over the elements in this stack (in proper sequence). The returned list iterator is fail-fast. Syntax: public ListIterator listIterator() Return Value: This method returns a list iterator over the elements in this s 2 min read Stack listIterator(int) method in Java with Example The listIterator(int) method of Stack Class is used to return a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list. The specified index indicates the first element that would be returned by an initial call to next. An initial call to pre 2 min read AbstractList listIterator() Method in Java with Examples The listIterator() method of java.util.AbstractList class is used to return a list-iterator containing the same elements as that of the AbstractList in proper and same sequence starting from a specific position or index number which is passed as a parameter to this method. Syntax: ListIterator new_l 2 min read List add() Method in Java with Examples The List add() method adds (appends) an element to a list. It can be used for both ArrayList and LinkedList. Example of List add() Method: Java // Java program to demonstrate // ArrayList usage import java.io.*; import java.util.ArrayList; import java.util.List; class GFG { public static void main ( 3 min read List get() method in Java with Examples The get() method of List interface in Java is used to get the element present in this list at a given specific index. Example:Java// Java Program to demonstrate List // get() Method import java.util.*; class Main { public static void main (String[] args) { // Create a List List<Integer> a=new 2 min read List size() method in Java with Examples The size() method of the List interface in Java is used to get the number of elements in this list. That is, the list size() method returns the count of elements present in this list container.Example:Java// Java Program to demonstrate // List size() Method import java.util.*; class GFG { public sta 2 min read List clear() method in Java with Examples The clear() method of List interface in Java is used to remove all of the elements from the List container. This method does not deleted the List container, instead it just removes all of the elements from the List. Example:Java// Java Program to Demonstrate // List clear() import java.util.*; class 2 min read List equals() Method in Java with Examples The List equals() method is used to compare two lists. It compares the lists as, both lists should have the same size, and all corresponding pairs of elements in the two lists are equal. Implementation:Java// Java code to show the implementation of // addAll method in list interface import java.util 2 min read Like