Clear a List

ReturnMethodSummary
voidclear()Removes all of the elements from this list (optional operation).

import java.util.ArrayList;
import java.util.List;

public class Main {
  public static void main(String[] args) {
    List list = new ArrayList();

    list.add("1");
    list.add("2");
    list.add("3");
 
    list.add("java2s.com");

    System.out.println("List has:" + list);

    list.clear();
    
    System.out.println("List has:" + list);
    
  }
}

The output:


List has:[1, 2, 3, java2s.com]
List has:[]
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.