Java Collection Tutorial - Java ListIterator.set(E e)








Syntax

ListIterator.set(E e) has the following syntax.

void set(E e)

Example

In the following code shows how to use ListIterator.set(E e) method.

//w w w. ja v a2s.c  om
import java.util.ArrayList;
import java.util.ListIterator;

public class Main {
  public static void main(String[] args) {
    ArrayList<String> aList = new ArrayList<String>();

    aList.add("1");
    aList.add("2");
    aList.add("3");
    aList.add("4");
    aList.add("5");

    ListIterator<String> listIterator = aList.listIterator();
    listIterator.next();

    listIterator.set("100");
    for (String str : aList) {
      System.out.println(str);
    }
  }
}

The code above generates the following result.