Java List add and insert by ListIterator

Description

Java List add and insert by ListIterator




import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

public class Main {
  public static void main(String[] args) {
    List<String> aList = new ArrayList<String>();
    aList.add("HTML");
    aList.add("CSS");
    aList.add("Java");
    aList.add("Javascript");
    aList.add("demo2s.com");

    ListIterator<String> listIterator = aList.listIterator();
    listIterator.next();//from  w ww.  jav  a2s.c o  m
    listIterator.add("new");
    listIterator.add("new 1");
    listIterator.next();
    listIterator.add("new 2");
    
    System.out.println(aList);
    
  }
}



PreviousNext

Related