270
Java Collection removeIf() Method
The removeIf() method of Java Collection Interface removes the elements of this queue that satisfies the given predicate filter.
Syntax
Parameters
The parameter ‘filter’ represents a predicate which returns true for the elements to be removed.
Return Value:
The removeIf () method returns a Boolean value ‘true’ if the collection has removed any element, else it returns ‘false’.
Throws
UnsupportedOperationException– if the elements cannot be removed from this collection.
NullPointerException– if the specified filter is null.
Example 1
Output:
Total no : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] Table of 2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
Example 2
Output:
People who passed the exam : 1. Reema has passed the exam with 98 marks. 2. Raj has passed the exam with 71 marks. 3. Ravi has passed the exam with 47 marks.
Example 3
Output:
Albabets : [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z] Vowels = [A, E, I, O, U]
Next TopicJava-Collection