RemoveAll () method
Privatestaticvoid testlist () { Listnew arraylist<string>() ; ListNew arraylist<string>(); List.add ("123"); List.add ("456"); List1.add ("123"); List.removeall (list1); Iterator<String> Iterator = list1.iterator (); while (Iterator.hasnext ()) { System.out.println (Iterator.next ()); } }
// Output Results 456
//clear () method
Private Static voidtestlist () {List<String> list =NewArraylist<string>(); List<String> List1 =NewArraylist<string>(); List.add ("123"); List1.add ("123"); List.add ("456"); List.clear (); Iterator<String> iterator =List.iterator (); while(Iterator.hasnext ()) {System.out.println (Iterator.next ()); } if(List = =NULL) {System.out.println ("NULL"); }Else if(List.size () ==0) {System.out.println ("List is not NULL" + "number of elements" +list.size ()); }Else{System.out.println ("Still have elements"); } }
// output list not a null element number is 0
The difference between the RemoveAll (collection<e> Col) and the clear method of the list collection