To insert an object into a specific position into the list, specify the index in the add method. - Java Collection Framework

Java examples for Collection Framework:ArrayList

Description

To insert an object into a specific position into the list, specify the index in the add method.

Demo Code

import java.util.LinkedList;

public class Main {
  public static void main(String[] args) {
    LinkedList<String> officers = new LinkedList<String>();
    officers.add("Blake");
    officers.add("Burns");
    officers.add("Jack");
    officers.add("P");
    officers.add("Tom");
    officers.add(2, "new");
    for (String s : officers)
       System.out.println(s);//from   ww  w.  j a v  a  2 s .co  m
  }
}

Related Tutorials