Create an object array from elements of LinkedList - Java Collection Framework

Java examples for Collection Framework:LinkedList

Description

Create an object array from elements of LinkedList

Demo Code

 
import java.util.LinkedList;
 
public class Main {
 
  public static void main(String[] args) {
    LinkedList lList = new LinkedList();
   /*from  w  ww  .j ava  2  s. co m*/
    //add elements to LinkedList
    lList.add("1");
    lList.add("2");
    lList.add("3");
    lList.add("4");
    lList.add("5");
   
     Object[] objArray = lList.toArray();
   
     System.out.println("Object array created from Java LinkedList.");
     System.out.println("Object array contains : ");
   
     for(int i=0; i<objArray.length ; i++)
     {
       System.out.println(objArray[i]);
     }
  }
}

Result


Related Tutorials