logo       

Collection sorting: msg#00186

lang.groovy.user

Subject: Collection sorting

Hi all

Just browsing through the groovy reference summary i notice the
collection.sort(){..} closure support. Obviously on the sheet it
doesnt actually show one how it operates except to indicate the
closure acts as a comparator, I just need to work out how to use this
can anyone give me an example, i was thinking this kind of thing :

myCollectionOfNumbers.sort() {key | return it < key ? -1 : (it == key ? 0 : 1)}

to sort a collection of integers

I may be well of base here not being a groovy expert, my actual
problem is also more complex it's a collection of stings that i wish
to arrange alphabetically or numerically (even though some arent real
numbers)

Anyone care to touch me with a clue stick ..
--
regards
babelex


#OpenSource means free to innovate#



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise