In a previous post, we learned about the intersect method being 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:

Source de l’article sur DZONE

0 réponses

Laisser un commentaire

Participez-vous à la discussion?
N'hésitez pas à contribuer!

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée.