July 2013
Intermediate to advanced
370 pages
8h 27m
English
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 Section 6.6, 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 ... |
Read now
Unlock full access