Java Collection removeIf() Method24 Mar 2025 | 2 min read The removeIf() method of Java Collection Interface removes the elements of this queue that satisfies the given predicate filter. SyntaxParametersThe 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'. ThrowsUnsupportedOperationException- if the elements cannot be removed from this collection. NullPointerException- if the specified filter is null. Example 1Output: 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 2Output: 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 3Output: 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 |
Java method The addAll() method of Java Collection Interface appends or inserts all the elements of the specified collection to this collection. Syntax boolean addAll(Collection<? extends E> c) Parameters The parameter 'c' represents the elements to be added into this Collection. Return Value The addAll() method returns a Boolean value...
3 min read
Java Method The hashCode() method of Java Collection Interface returns the hash code value for this collection. Syntax public int hashCode() Parameters NA Overrides This method overrides hashCode in class Object Return The hashCode() method returns the hash code value for this collection. Example 1 import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; public class JavaCollectionHashCodeExample1 { ...
1 min read
Java Method The contains() method of Java Collection Interface returns a Boolean value 'true', if it contains the specified element in the collection. Syntax public boolean containsAll(Object o) Parameters The parameter 'o' represents the element whose occurrence in this collection is to be tested. Throws ClassCastException- if the type of the...
3 min read
Java method The add() method of Java Collection Interface inserts the specified element in this Collection. It returns a Boolean value 'true', if it succeeds to insert the element in the specified collection else it returns 'false'. Syntax public boolean add(E e) Parameters The parameter 'e' represents the element...
3 min read
Java Method The containsAll() method of Java Collection Interface returns a Boolean value 'true', if this collection contains all the elements in the invoked collection. Syntax public boolean containsAll(Collection<?> c) Parameters The parameter 'c' represents the collection to be checked for occurrence in this collection. Throws ClassCastException- if the types of...
3 min read
Java Method The isEmpty() method of Java Collection Interface returns the boolean value 'true' if this collection contains no elements. Syntax public boolean isEmpty() Parameters NA Return The isEmpty () method returns the boolean value 'true' if this collection contains no elements else it returns false. Example 1 import java.util.Collection; import java.util.concurrent.ConcurrentLinkedQueue; public class JavaCollectionIsEmptyExample1...
2 min read
Java Method The equals() method of Java Collection Interface compares the specified object with this collection for equality. Syntax public boolean equals(Object o) Parameters The parameter 'o' represents the object to be compared for equality with this collection. Overrides This method overrides equals in class Object Return The equals method returns Boolean value...
2 min read
Java Method The toArray() method of Collection Interface returns an array containing all the elements present in the collection. The second syntax returns an array containing all of the elements in this collection where the runtime type of the returned array is that of the specified...
3 min read
Java method The size() method of Java Collection Interface returns the total count of the elements contained in this collection. Syntax public int size() Parameters NA Return Value The size() method returns the total count of the elements present in this collection. Example 1 import java.util.Collection; import java.util.HashSet; public interface JavaCollectionSizeExample1 { ...
3 min read
Java Method The spliterator() method of Collection Interface returns a Spliterator across the elements of this collection. Syntax public Spliterator<E>spliterator() Parameters NA Specified By The spliterator() method of Collection class is specified by: Spliterator() method in interface Iterable<E>. Return Value The spliterator() method returns a Spliterator across the elements of this collection. Example 1 import java.util.Collection; import...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India