donguy76
donguy76

Reputation: 640

Find items from List based on matching property

I have a Groovy class:

class GlobalUsers {

    String name = ""
    String ID = ""
    ................
    ................
}

Now in another function:

List<GlobalUsers> guObjs = new List<GlobalUsers>();

Here I have few hundreds of objects of GlobalUsers in a List.

I want to find all objects of GlobalUsers where string name == "User_CUSTOM"

So basically the result will be another List:

List<GlobalUsers> guObjs = *name == "User_CUSTOM"*

Upvotes: 1

Views: 4439

Answers (1)

ataylor
ataylor

Reputation: 66069

You can use the findAll() method:

def globalUsers = guObjs.findAll { it.name == "User_CUSTOM" }

Upvotes: 4

Related Questions