Java – how to sort ArrayList in dictionary order?

I'm trying to sort the string ArrayList representing the card value Therefore, some cards contain letters ("King") and some contain strings containing only numbers ("7") I know how to use collections Sort, but it only sorts strings containing letters How do I sort ArrayList by row number and alphabetically?

Editor: sorry, I won't pay much attention when I check the sorting In normal order, I have to be abandoned by a fact before 10 comes to 2 thank you

Solution

No, collections Sort will sort everything using Unicode ordinal dictionary comparison because this is string CompareTo's behavior "7" will appear before "King" and "10" will appear before "2"

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>