Speaking of the Elvis operator, try this one:
That's a sort by length, and if the lengths are equal (i.e., the sizes are the same so <=> returns 0), it sorts lexicographically (which is alphabetically with capital letters ahead of lowercase letters). More importantly, it shows Elvis being carried back to his home planet by two tandem spaceships, so it's the fat Elvis from the 70s rather than the thin Elvis from the 50s.
Yeah, that's a long way to go for such a silly gag, but I still find it amusing. More generally, if you wanted to sort strings by length in Java, you'd write:
The Groovy JDK adds a sort method to collections, so you don't need the Collections class at all. The sort method also takes a one- or two-argument closure. If you use the two-arg closure, you supply a typical comparator, as in:
If you use the one-arg closure, then just return something that can be used for the sort (typically an integer), so the whole length sort reduces to:
and you're done. Hard to be much simpler than that.
![](https://coderanch.com/images/smilies/3b63d1616c5dfcf29f8a7a031aaa7cad.gif)