Java Collection removeIf() 方法

2025年3月24日 | 阅读时间:2 分钟

Java Collection 接口的 removeIf() 方法会移除此队列中满足给定谓词过滤器的元素。

语法

参数

参数 'filter' 表示一个谓词,它为要移除的元素返回 true。

返回值

如果集合移除了任何元素,removeIf() 方法将返回布尔值 'true',否则返回 'false'。

抛出

UnsupportedOperationException - 如果无法从此集合中移除元素。

NullPointerException - 如果指定的过滤器为 null。

示例 1

输出

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]

示例 2

输出

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.

示例 3

输出

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]
下一个主题Java-Collection