Remove all elements or clear LinkedList - Java Collection Framework

Java examples for Collection Framework:LinkedList

Description

Remove all elements or clear LinkedList

Demo Code

 
import java.util.LinkedList;
 
public class Main {
 
  public static void main(String[] args) {
    LinkedList lList = new LinkedList();
    //add elements to LinkedList
    lList.add("1");
    lList.add("2");
    lList.add("3");
    lList.add("4");
    lList.add("5");
 
    System.out.println("LinkedList contains : " + lList);
    lList.clear();/*w ww .j  a v  a2  s .co  m*/
    System.out.println("LinkedList now contains : " + lList);
  }
}

Result


Related Tutorials