saurav
saurav

Reputation: 424

Sorting in Groovy

I have the below code with a list as:

def l = ['a','e','A','x','Z','p','Q']
println(l.sort())

Which generates output as:

[A, Q, Z, a, e, p, x]

Now, I know that this is ASCII based sorting, I just want to get the correct result. What are the possible solutions for this situation? What I want is something like:

[A, a, e, p, Q, x, Z]

Upvotes: 0

Views: 78

Answers (1)

Opal
Opal

Reputation: 84756

Try:

['a','e','A','x','Z','p','Q'].sort { it.toLowerCase() }

Upvotes: 3

Related Questions