The removeIf() method of Vector removes all of those elements from Vector which satisfies the condition passed as a parameter to this method. This method returns true if some element are removed from the Vector.
Java 8 has an important in-built functional interface which is Predicate. Predicate, or a condition checking function, which checks the given input for a given condition and returns a boolean result for the same indicating whether the condition was met or not.
public boolean removeIf(Predicate<? super E> filter)
Parameter: This method takes a parameter filter which represents a predicate which returns true for elements to be removed.
Returns: This method returns True if predicate returns true and some elements were removed.
Exception: This method throws NullPointerException if the specified filter is null.
Below programs illustrate removeIf() method of Vector:
Example 1: To demonstrate removeIf() method on vector which contains a set of Numbers and only the numbers which are divisible by 2 will be removed.
All Numbers not divisible by 2 are: 33 55
Example 2: To demonstrate removeIf() method on Vector which contains set of Students Names and to remove all 4 char long name.
Students name do not contain 4 char are Mohan Sohan Shabbir
Example 3: To demonstrate NullpointerException in removeIf() method on Vector.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- ArrayList removeIf() method in Java
- CopyOnWriteArrayList removeIf() method in Java with Examples
- LinkedBlockingDeque removeIf() method in Java with Examples
- LinkedTransferQueue removeIf() method in Java with Examples
- CopyOnWriteArraySet removeIf() method in Java with Examples
- Java 8 | ArrayDeque removeIf() method in Java with Examples
- Vector set() Method in Java
- Vector get() Method in Java
- Vector contains() Method in Java
- Vector add() Method in Java
- Vector equals() Method in Java
- Vector elements() Method in Java
- Vector elementAt() Method in Java
- Vector indexOf() Method in Java
- Vector addAll() Method in Java
- Vector clear() Method in Java
- Vector setElementAt() method in Java with Example
- Vector capacity() Method in Java
- Vector containsAll() Method in Java
- Vector copyInto() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.