Other Convenience Methods on Maps

Let’s wrap up our discussion of collections by looking at a few convenience methods of Map.

We saw how the find method is useful for fetching an element that satisfies a given condition. However, instead of getting the element, if we’re simply interested in determining whether any elements in the collection satisfy some condition, we can use the any method.

Let’s continue with the example of languages and authors from Iterating Over Map. We can use the any method to determine whether any language name has a nonalphabetic character:

WorkingWithCollections/NavigatingMap.groovy
 
print ​"Does any language name have a nonalphabetic character? "
 
println langs.any { language, author ->
 
language =~ ​"[^A-Za-z]" ...

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.