Groovy Collections
Groovy offers many enhancements to the standard Java collection classes. We’ll take a look at the three collection types that are most used in Grails. The List, Map, and Set are powerful tools, and Groovy gives them a new edge. We know—technically Map is not a collection; that is, it does not implement the Collection interface. But for our purposes, it is a collection in that it holds objects. So, leaving semantic sensitivities aside, let’s look at what Groovy has done for these classes.
List
One of the first interesting things to learn about the List in Groovy is that it can be created with a literal declaration.
introduction.2/groovy_list.groovy | |
| def colors = ['Red', 'Green', 'Blue', 'Yellow'] |
| def empty = ... |
Get Grails 2: A Quick-Start Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.