Collections 如何在Groovy中获得列表的不匹配子集
我有两组类型字符串列表Collections 如何在Groovy中获得列表的不匹配子集,collections,groovy,Collections,Groovy,我有两组类型字符串列表 def allExecPerms // has 500 elements nearly def dbExecPerms // has 550 elements nearly 列表allExecPerms是dbExecPerms的子集,我试图在不迭代dbExecPerms的情况下获取不匹配的元素子集,并将每个元素都映射到allExecPerms中 def unmatchedExecs = [] dbExecPerms.each { if(!allExec
def allExecPerms // has 500 elements nearly
def dbExecPerms // has 550 elements nearly
列表allExecPerms是dbExecPerms的子集,我试图在不迭代dbExecPerms的情况下获取不匹配的元素子集,并将每个元素都映射到allExecPerms中
def unmatchedExecs = []
dbExecPerms.each {
if(!allExecPermissions.contains(it))
unmatchedExecs.add(it)
}
我想知道以一种更简单的方式使用groovy闭包是否可行?groovy可以通过以下方式为您做到这一点:
(dbExecPaams as Set) - allExecParams
要实现设置差异操作,请执行以下操作:
公共集减号(集合移除)
参数:
removeMe—要从集合中删除的项目
返回:
结果集
自:
1.5.0
我意识到这一点已经得到了回答,但是Groovy的
findAll
方法设计用于根据以下条件收集列表中的元素:
def unmatchedExecs = dbExecPerms.findAll {
!allExecPermissions.contains(it)
}
对于文档:感谢您提供了简单的修复和解释,我对groovy非常陌生,我工作得越多,我就越喜欢……)
def unmatchedExecs = dbExecPerms.findAll {
!allExecPermissions.contains(it)
}