This is a Java program that removes all elements from an ArrayList using the removeAll method. Here's how the program works:
import java.util.ArrayList; import java.util.Collections; public class Empty_ArrayList { public static void main(String[] args) { ArrayList<String> str_col= new ArrayList<String>(); str_col.add("Black"); str_col.add("Orange"); str_col.add("Pink"); str_col.add("Blue"); str_col.add("White"); str_col.add("Yellow"); System.out.println("Original array list: " + str_col); str_col.removeAll(str_col); System.out.println("Array list after removing all elements "+ str_col); } }
Original array list: [Black, Orange, Pink, Blue, White, Yellow] Array list after removing all elements []
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions