জাভাতে ArrayList থেকে সমস্ত উপাদান অপসারণ করতে, আসুন প্রথমে কিছু উপাদান সহ একটি ArrayList তৈরি করি -
ArrayList<Integer> arrlist = new ArrayList<Integer>(5); arrlist.add(25); arrlist.add(50); arrlist.add(75); arrlist.add(100); arrlist.add(150); arrlist.add(200); arrlist.add(250);
এখন, আসুন সমস্ত উপাদান মুছে ফেলি -
arrlist.clear();
উদাহরণ
এখন সম্পূর্ণ কোড −
দেখিimport java.util.ArrayList; public class Demo { public static void main(String[] args) { ArrayList<Integer> arrlist = new ArrayList<Integer>(5); arrlist.add(25); arrlist.add(50); arrlist.add(75); arrlist.add(100); arrlist.add(150); arrlist.add(200); arrlist.add(250); for (Integer number : arrlist) { System.out.println("Number = " + number); } int retval = arrlist.size(); System.out.println("List consists of "+ retval +" elements"); System.out.println("Performing clear operation!!"); arrlist.clear(); retval = arrlist.size(); System.out.println("Now, list consists of "+ retval +" elements"); } }
আউটপুট
এটি নিম্নলিখিত আউটপুট −
তৈরি করবেNumber = 25 Number = 50 Number = 75 Number = 100 Number = 150 Number = 200 Number = 250 List consists of 7 elements Performing clear operation!! Now, list consists of 0 elements