Replace an element from ArrayList using Java ListIterator : ListIterator « Collections « Java Tutorial






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);
    }
  }
}








9.38.ListIterator
9.38.1.ListIterator: Like an Iterator
9.38.2.Iterate through elements ArrayList using ListIterator
9.38.3.ListIterator: In reverse order
9.38.4.Get Previous and next index using Java ListIterator
9.38.5.Add or insert an element to ArrayList using Java ListIterator
9.38.6.Remove an element from ArrayList using Java ListIterator
9.38.7.Replace an element from ArrayList using Java ListIterator
9.38.8.Modifying the list that the iterator came from: add(), remove(), and set()
9.38.9.Iterate through elements of Java LinkedList using ListIterator