I know i can make use of sort() function in Groovy to sort List. For example I can do this :
def numbers = [1,4,3] as List
print numbers.sort() // outputs : [1,3,4]
Now i want to know whether there is a function in Groovy, which does something like this:
def number = 143
// any method there to apply on number, so that i can get 134 as output!?
// that is i get sorted my number?
Correct me if am wrong!
This should work:
That:
"$number"collects each char as an int (so you get a List of int)sort()on this arrayjoin()to stick all the ints back together as a Stringas intto convert this String back into an intAs an aside, you don’t need to do:
in your example code…
[1,4,3]is aListalready, soas Listis superfluous