Get elements from LinkedList - Java Collection Framework

Java examples for Collection Framework:LinkedList

Description

Get elements from LinkedList

Demo Code

 
import java.util.LinkedList;
 
public class Main {
 
  public static void main(String[] args) {
 
    //create LinkedList object
    LinkedList lList = new LinkedList();
   //from w  w w.ja va  2  s  . c  o  m
    //add elements to LinkedList
    lList.add("1");
    lList.add("2");
    lList.add("3");
    lList.add("4");
    lList.add("5");
   
    System.out.println("LinkedList contains : ");
    for(int i=0; i< lList.size(); i++)
    {
      System.out.println(lList.get(i));
    }
  }
}
 

Result


Related Tutorials