Groovy Goodness: Removing Duplicate Elements in a Collection - Messages from mrhaki
Groovy Goodness: Removing Duplicate Elements in a CollectionWe can easily remove duplicate elements in a collection with the different
view sourceprint?unique()
methods. Without any parameters the default comparator for the objects is used to determine duplicate elements. But we can also use a closure to define the rules for duplicate elements. The closure can have one parameter and then we must return a value that is used for comparison, or the closure has two parameters and then we must return an Integer value where 0 means the items are not unique. Finally we can pass our ownComparator
implementation to theunique()
method where we define when an element is unique or not.欢迎分享,转载请注明来源:内存溢出
评论列表(0条)