How to Remove All Items From an ArrayList in Java


In this example we will show the method to remove all items from an ArrayList in Java.

Source Code

package com.beginner.examples;

import java.util.ArrayList;

public class ClearArrayList { 
  public static void main(String[] args) { 
    ArrayList strs = new ArrayList();
    strs.add("a");
    strs.add("b");
    strs.add("c");
    strs.clear(); // remove all items
    System.out.println(strs);
  } 
}

Output:

[]

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments