VOOZH about

URL: https://www.geeksforgeeks.org/java/copyonwritearrayset-removeif-method-in-java-with-examples/

⇱ CopyOnWriteArraySet removeIf() method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

CopyOnWriteArraySet removeIf() method in Java with Examples

Last Updated : 11 Jul, 2025
The removeIf() method of CopyonWriteArraySet method removes the element from this CopyOnWriteArraySet that satisfies the specified condition. Syntax:
public boolean removeIf (Predicate<E> filter)
Parameters: This method accepts a mandatory parameter filter which is the predicate value based on which elements are removed from this set. Return Value: This method returns a boolean value such as true, if the CopyOnWriteArraySet is changed. Else this method returns false. Exceptions: This method throws NullPointerException if the specified Predicate filter is null. Below program illustrates the removeIf() function of CopyOnWriteArrayList class : Program 1:
Output:
CopyOnWriteArraySet: [10, 20, 30, 40, 50, 60, 70, 80, 90]
Updated CopyOnWriteArraySet: [10, 20, 40, 50, 70, 80]
Program 2:
Output:
CopyOnWriteArraySet: [GeeksforGeeks, GFG, Geeks, Gfg]
java.lang.NullPointerException
Comment