开发者

Groovy sorting string asc

开发者 https://www.devze.com 2022-12-24 21:07 出处:网络
How to sort string names in array on ascending order . I tried sort methodbut it fails to sort on name basis .

How to sort string names in array on ascending order .

I tried sort method but it fails to sort on name basis .

def words = ["oran开发者_开发百科ge", "blue", "apple", "violet", "green"]

I need to achieve like this :

["apple", "blue", "green", "orange", "violet" ]

thanks in advance.


["orange", "blue", "apple", "violet", "green"].sort()


def words = ["orange", "blue", "apple", "violet", "green"]

["orange", "blue", "apple", "violet", "green"].sort({ a, b -> a[0] <=> b[0] } as Comparator )

You can also change the indexes based on the requirement

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号