Remove all elements from ArrayList in Java

Description

The following code shows how to remove all elements from ArrayList.

Example


//from   w ww.j  av  a2 s. c  o  m
import java.util.ArrayList;

public class Main {

  public static void main(String[] args) {

    ArrayList<String> arrayList = new ArrayList<String>();

    arrayList.add("1");
    arrayList.add("2");
    arrayList.add("java2s.com");

    System.out.println(arrayList.size());

    arrayList.clear();

    System.out.println(arrayList.size());

  }

}

The code above generates the following result.





















Home »
  Java Tutorial »
    Java Collection »




Java ArrayList
Java Collection
Java Comparable
Java Comparator
Java HashMap
Java HashSet
Java Iterator
Java LinkedHashMap
Java LinkedHashSet
Java LinkedList
Java List
Java ListIterator
Java Map
Queue
Java Set
Stack
Java TreeMap
TreeSet