VOOZH about

URL: https://www.geeksforgeeks.org/java/concurrentskiplistset-removeall-method-in-java/

⇱ ConcurrentSkipListSet removeAll() method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

ConcurrentSkipListSet removeAll() method in Java

Last Updated : 26 Nov, 2018
The removeAll() method of java.util.concurrent.ConcurrentSkipListSet is an in-built function in Java which returns removes from this set all of its elements that are contained in the specified collection. If the specified collection is also a set, this operation effectively modifies this set so that its value is the asymmetric set difference of the two sets. Syntax:
public boolean removeAll(Collection c)
Parameter: The function accepts a single parameter c Return Value: The function returns true if this set changed as a result of the call. Exception: The function throws the following exceptions:
  • ClassCastException - if the types of one or more elements in this set are incompatible with the specified collection
  • NullPointerException - if the specified collection or any of its elements are null
  • Below programs illustrate the ConcurrentSkipListSet.removeAll() method: Program 1:
    Output:
    Contents of the list: [1, 3, 5, 7, 9]
    Contents of the set: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    Contents of the set after removal: [2, 4, 6, 8, 10]
    
    Program 2: Program to show NullPOinterException in removeAll().
    Output:
    Contents of the set: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    Exception: java.lang.NullPointerException
    
    Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#removeAll-java.util.Collection-
    Comment