-
StackOverflow 文件
-
groovy 教程
-
收集運算子
-
刪除重複項
def lst = ['foo', 'foo', 'bar', 'baz']
// *modifies* the list removing duplicate items
lst.unique() // [foo, bar, baz]
// setting to false the "mutate" argument returns a new list, leaving the original intact
lst.unique(false) // [foo, bar, baz]
// convert the list to a Set, thus removing duplicates
lst.toSet() // [baz, bar, foo]
// defining a custom equality criteria. For example: to elements are equal if have the same first letter
println lst.unique() { it[0] } // [foo, bar]. 'bar' and 'baz' considered equal