Insert an Element into LinkedList - Java Collection Framework

Java examples for Collection Framework:LinkedList

Description

Insert an Element into LinkedList

Demo Code

 
import java.util.LinkedList;
 
public class Main {
 
  public static void main(String[] args) {
    LinkedList lList = new LinkedList();
   /* ww w  .  ja  va  2s  . c  o  m*/
    lList.add("1");
    lList.add("2");
    lList.add("3");
    lList.add("4");
    lList.add("5");
   
    System.out.println("LinkedList contains : " + lList);
   
    lList.add(2, "2.5");
    System.out.println("After inserting 2.5, LinkedList contains : " + lList);
   
  }
}
 

Result


Related Tutorials