Anonymous user
Remove duplicate elements: Difference between revisions
→{{header|Groovy}}: more Groovyish
(→{{header|Groovy}}: more Groovyish) |
|||
Line 1,231:
<lang groovy>def list = [1, 2, 3, 'a', 'b', 'c', 2, 3, 4, 'b', 'c', 'd']
assert list.size() == 12
println " Original List: ${list}"
// Filtering the List (non-mutating)
def list2 = list.unique(false)
assert list.size() == 12
// Filtering the List (in place)
list.unique()
assert list.size() == 8
println "
assert
// Converting to Set
def set =
▲assert set.size() == 8
▲println " Set: ${set}"
assert set.size() == 8
println "
{{out}}
|