Groovy Goodness: Intersect Collections With Custom Comparator

In a previous post we learned about the intersect method added to collections in Groovy. Since Groovy 2.5.0 we can supply a custom Comparator to the intersect method to define our own rules for the intersection.

In the following example we first apply the intersect method with the default Comparator. Then we create a new Comparator using a closure where we check if the value is in both collections and if the value starts with the letter M:

Written with Groovy 2.5.0.

Original post

This entry was posted in Coding, Groovy and tagged by mrhaki. Bookmark the permalink.

About mrhaki

My name is Hubert A. Klein Ikkink also known as mrhaki. I work at the great IT company JDriven. Here I work on projects with Groovy & Grails, Gradle and Spring. At JDriven we focus on SpringSource technologies. All colleagues want to learn new technologies, support craftmanship and are very eager to learn. This is truly a great environment to work in. You can contact me via Google+ or @mrhaki.

Leave a Reply

Your email address will not be published. Required fields are marked *