noob
noob

Reputation: 300

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.

Is it even possible? Or is their anyway around this?

Upvotes: 0

Views: 79

Answers (1)

Amadan
Amadan

Reputation: 198314

I don't know Groovy, but by a quick Google, something non-bulky like this should work:

def found = officers.findAll { it.name =~ /Mar/ }

Upvotes: 5

Related Questions