Groovy web console

subscribe to the feed Subscribe
to this
site
groovy sort and toSort (via #groovywebconsole)
tweet this snippet Tweet
this
script

groovy sort and toSort

Published 2 months ago by Joe with tags dangerous sort
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def initial = [1,3,5,4]
def sorted = initial.toSorted{ a, b -> a <=> b}

println("initial after custom toSort=$initial")
println("sorted=$sorted")

initial.sort()
println("initial after dangerous sort=$initial")