简体   繁体   English

搜索列表中的元素

[英]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.

相关问题 如何搜索列表中的元素? - How to search element in a List? 从硒的搜索列表中打印元素的索引 - print index of an element from the search list in selenium 在某个值之后搜索列表中的最小元素 - Search for the smallest element in a list after some value 搜索ArrayList的一个元素并返回包含该元素的所有对象的List - Search for one element of an ArrayList and return a List of all objects that contains that element 如何搜索一个列表中的 en 元素是否存在于另一个列表中的元素中,然后打印该元素 - How can I search if en element from one List exists in the elements in the other list and then print this element 大O表示法要访问链表和二进制搜索中的中间元素? - Big O notation For accessing middle element in linked list and binary search? 如何按日期排序列表,然后在第一个位置搜索元素和设置 - How to order a list by date and then search a element and setting at first position 在带有搜索列表的下拉列表中找不到Appium By.name中的元素 - Not able to find Element in Appium By.name in dropdown with search list 如何搜索多个下拉列表中的下一个元素 - How do I search the next element in a list of multiple dropdowns 如何从搜索返回的元素列表中单击随机元素 - How to Click Random element from a list of elements returned by a search
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM