Java LinkedList add elements

Introduction

To add elements to LinkedList in Java

linkedList.add(object);

Full source

import java.util.Arrays;
import java.util.LinkedList; 
 
public class Main { 
  public static void main(String args[]) { 
    // Create an array list. 
    LinkedList<String> al = new LinkedList<String>(); 
     /*from  w w w.java2  s .  c  om*/
    // Add elements to the array list. 
    al.add("SQL"); 
    al.add("Java"); 
    al.add("Javascript"); 
    al.add("CSS"); 
    al.add("HTML"); 
    al.add("Demo2s.com"); 
    al.add(1, "Hi"); 
 
    System.out.println(al);
    
    // Get the array. 
    String ia[] = new String[al.size()];  
    ia = al.toArray(ia);  
    
    System.out.println(Arrays.toString(ia));
  } 
}



PreviousNext

Related