Chapter 6Working with Collections

We use collections extensively when programming. The Java Development Kit (JDK) has a number of useful collections, and Groovy extends those collections, making them more convenient to use. For example, we can use internal iterators, which are concise, easier to use, and less error-prone than the traditional for loop. We can use a different specialized iterator, find, to pick an element from a collection. To pick several matching elements we simply change find to findAll, and the rest of the code remains the same—concise, no extra baggage of the new collection to carry around. Once we get used to the collections in Groovy, it’s pretty hard to go back and use the Java API for these collections. You’ve been warned! ...

Get Programming Groovy 2 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.