FAQ - Collections, Lists, etc. Add comment to Wiki View in Wiki Edit Wiki page Printable Version

Collections, Lists, etc.

Why don't return statements work when iterating through an object?

The {...} in an each statement is not a normal Java block of code, but a closure. Closures are like classes/methods, so returning from one simply exits out of the closure, not the enclosing method.

How do I declare and initialize a list at the same time?

Syntax:

How do I declare and initialize a traditional array at the same time?

Syntax:

or

or

Why does myMap.size or myMap.class return null?

In Groovy, maps override the dot operator to behave the same as the index[ ] operator:

Why is my map returning null values?

Chances are, you tried to use a variable as a key in a map literal definition.

Remember, keys are interpreted as literal strings:

Try this (note the parentheses around the key):

 

Search

Results of your search request can come from various sources: the Groovy website itself, the JIRA issues, the API documentation, as well as a few other interesting Groovy-related blogs.

  By  -  pages  -  views  - last modified