Unique closure on more than one field.
In one of my recent grails project, I had a requirement to get unique objects from a list based on more than one field. Now, this can be done by passing the list to closure unique.
I had a list of dates of a couple of years, and what I needed was a unique combination of month and year.
List dates
date.unique{[it.month,it.year]}
Hi Hitesh,
That’s really helpful post. Unless we used to take TreeSet to avoid duplication.
Thanks for this valuable concept.
Regards,
Subrata
Hi Subrata
yes ..that would have been good alternative ..
Thnx