两个List< String>的有效交集在Java? [英] Efficient intersection of two List<String> in Java?

查看:104
本文介绍了两个List< String>的有效交集在Java?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题很简单:

我有两个清单

List<String> columnsOld = DBUtils.GetColumns(db, TableName);
List<String> columnsNew = DBUtils.GetColumns(db, TableName);

我需要得到这些的交集。有没有快速实现此目的?

And I need to get the intersection of these. Is there a quick way to achieve this?

推荐答案

您可以使用 retainAll 方法:

You can use retainAll method:

columnsOld.retainAll (columnsNew);

这篇关于两个List&lt; String&gt;的有效交集在Java?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆