Write a Java program to empty an array list

Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..

import java.util.ArrayList;
import java.util.Collections;
  public class Javacollectionexcercise {
  public static void main(String[] args) {
        ArrayList<String> Stringslist1= new ArrayList<String>();
        Stringslist1.add("Audi");
        Stringslist1.add("BMW");    
        Stringslist1.add("Bugatti");
        Stringslist1.add("Ford");
        Stringslist1.add("Honda");
        Stringslist1.add("Hyundai");
          System.out.println("Original array list: " + Stringslist1);
          Stringslist1.removeAll(Stringslist1);
          System.out.println("Array list after removing all elements "+ Stringslist1);   
   }
}

Result

Write a Java program to empty an array list
Write a Java program to empty an array list

Leave a Comment