The collect() method in Groovy can be used to iterate over collections and transform each element of the collection. The transformation is defined in as a closure and is passed to the collect() method. But we can also add an initial collection to which the transformed elements are added.
- collect(Collection collector, Closure transform)
- collect(Closure transform)
Below is the sample code:
* Groovy JDK enhancements - Collection interface