Saturday 26 January 2019

Groovy: Remove all the elements from list


‘clear()’ method removes all the elements from list.

HelloWorld.groovy
numbers = [0, 1, 2, 3, 4, 5, 3, 2, 1, 10]
println "numbers : $numbers"

println 'Clearing all the elements from numbers'
numbers.clear()

println "numbers : $numbers"

Output
numbers : [0, 1, 2, 3, 4, 5, 3, 2, 1, 10]
Clearing all the elements from numbers
numbers : []


Previous                                                 Next                                                 Home

No comments:

Post a Comment