From the course: Learning Groovy

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Working with Collections

Working with Collections - Groovy Tutorial

From the course: Learning Groovy

Start my 1-month free trial

Working with Collections

- [Instructor] The collection API in Groovy applies the concept of closures quite heavily, making it more convenient to use and, quite frankly, more fun. I want to show some methods for querying, filtering, sorting elements in a list. Keep in mind that you can apply similar convenience methods to other data types, like maps. In Groovy, you can create a new list with the help of square brackets. As with any other data type, you can assign it to a variable. Here, we're adding three persons to a list, assigned to the variable named allPersons. Let's first query the contents of the list, and ensure that the data type is a Java util list. Earlier, we used the dev keyword. As you can see, the size is three, and we can ask for specific elements in the list. In a previous video, we already talked about iterating over a collection with a for keyword. However, there's an easier way to achieve the same functionality. The each…

Contents