LinkedList boolean removeAll(Collection> c) method Example Program
By candid | Posted :
Jun 30, 2015
| Updated :
Jun 30, 2015
Removes from this list all of its elements that are contained in the specified collection (optional operation).
Program
package com.candidjava;
import java.util.LinkedList;
/*
* @author : Mohan
* @description : removeAll() method is used to remove all the elements in the list
*
*/
public class LinkedListRemoveAll {
public static void main(String[] args) {
LinkedList list = new LinkedList();
list.add("karthi");
list.add("mohan");
list.add("anand");
list.add("hari");
list.add("kamal");
System.out.println(list);
System.out.println("Is removed :" + list.removeAll(list));
System.out.println(list);
}
}
Output
[karthi, mohan, anand, hari, kamal]
Is removed :true
[]
Explanation
boolean removeAll(Collection c)
Removes from this list all of its elements that are contained in the specified collection (optional operation).
Specified by:
removeAll in interface Collection
Parameters:
c - collection containing elements to be removed from this list
Returns:
true if this list changed as a result of the call
Throws:
UnsupportedOperationException - if the removeAll operation is not supported by this list
ClassCastException - if the class of an element of this list is incompatible with the specified collection (optional)
NullPointerException - if this list contains a null element and the specified collection does not permit null elements (optional), or if the specified collection is null