[英]Search an element on a list
I have a this list in my code: 我的代码中有以下列表:
def officers = [[name:'Mark', surname: 'Pen'], [name:'Maria', surname: 'Charlote']]
now is it possible to search this list? 现在可以搜索此列表了吗? I mean something like 我的意思是
def found = officers.findNameLike('%Mar%')
and so it will return those 2 values since they have MAR char on their names. 因此将返回这两个值,因为它们的名称上有MAR char。
Is it even possible? 可能吗? Or is their anyway around this? 还是他们反正呢?
我不了解Groovy,但是通过快速的Google,类似这样的非大型项目应该可以工作:
def found = officers.findAll { it.name =~ /Mar/ }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.