当前位置:网站首页>集合删除元素技巧 removeIf
集合删除元素技巧 removeIf
2022-06-10 22:39:00 【Li_XiaoJin】
removeIf
removeIf() 是从 JDK1.8 开始提供的。
查看 API 文档:
删除满足给定谓词的此集合的所有元素。 在迭代或谓词中抛出的错误或运行时异常被转发给调用者。
之前我们删除 List 中的元素的话,一般使用循环遍历实现。今天发现 removeIf 很好用,记录一下。
以前做法:
List<String> testList = new ArrayList<>();
Iterator<String> it = testList.iterator();
while (it.hasNext()) {
if ("aa".equals(it.next())) {
it.remove();
}
}
现在可以使用:
testList.removeIf(s -> "aa".equals(s));
// 或者
testList.removeIf("aa"::equals);
Copyright: 采用 知识共享署名4.0 国际许可协议进行许可 Links:https://lixj.fun/archives/list删除元素技巧removeif
边栏推荐
- LabVIEW error "memory full - Application stopped on node"
- The data file insurance CSV contains 1338 observations, that is, the registered beneficiaries of the insurance plan and the characteristics that represent the characteristics of patients and the total
- Fiddler filtering sessions
- Dell R730 raid5 安装Server 2016(解决磁盘大于2T)
- 【LaTex】latex VS Code snippets(代码片段)
- [flutter problem series Chapter 6] how to achieve the scrolling effect of list messages in flutter
- 长投学堂开户安全吗?靠谱吗?
- LabVIEW调用DLL时出现异常0xc0000005代码
- MySQL table mechanism
- LabVIEW锁相环(PLL)
猜你喜欢

LabVIEW获取IMAQ Get Last Event坐标

Perfect decoding purecodec 20220601

MySQL table mechanism

The time (in minutes) required for a group of workers to cooperate to complete the assembly process of a part are as follows:

HyperLeger Fabric安装

怎么生成自动参考文献(简单 有图)

LabVIEW错误“内存已满 - 应用程序停止在节点”
![[Video] kmeans mean clustering and hierarchical clustering: R language analysis life happiness index visualization | data sharing](/img/d5/d544ab0c14ba22946219feafdc3392.png)
[Video] kmeans mean clustering and hierarchical clustering: R language analysis life happiness index visualization | data sharing

Prefer "big and small weeks", only write 200 lines of code every day, and the monthly salary of 8k-17k people will rise again

Developers changing the world - Yao Guang teenagers playing Tetris
随机推荐
Self made app connected to onenet --- realize data monitoring and distribution control (mqtt)
iframe框架自适应大小/全屏显示网页框架的方法
LabVIEW获取IMAQ Get Last Event坐标
一文带你了解J.U.C的FutureTask、Fork/Join框架和BlockingQueue
归并排序
LabVIEW或MAX下的VISA测试面板中串口无法工作
Vs tomato assistant add header comments and usage
[Video] kmeans mean clustering and hierarchical clustering: R language analysis life happiness index visualization | data sharing
LabVIEW用高速数据流盘
Simple impedance matching circuit and formula
Expandable to Max – MCU and MPU development, using the same license
【数学】【连续介质力学】流体力学中的对称张量、应变张量和应力张量
[flutter problem series Chapter 6] how to achieve the scrolling effect of list messages in flutter
Analysis of Genesis public chain
【无标题】
Dell R730 raid5 安装Server 2016(解决磁盘大于2T)
LabVIEW pictures look bright or dark after being cast from 16 bits to 8 bits
Postgraduate entrance examination English vocabulary unit1
How to handle the database query error with Emoji expression in Typecho- Xingze V Club
The shell script of pagoda plan task regularly deletes all files under a directory [record]