Selection Sorting String Arrays (Java)

前端 未结 4 932
情歌与酒
情歌与酒 2020-12-20 01:18

I need to know how to sort an array of Strings, I know how to do a selection sort, however I have BOTH numbers and letters in the array. The idea is to sort a hand of cards.

4条回答
  •  情话喂你
    2020-12-20 01:46

    Use Collections to do this for you. A sorted collection like a TreeMap will sort as you fill it. Collections with a sort method can be sorted after loading.

    If you need a custom sort order, you can provide your own Comparator. Arrays allow you to provide your own Comparator. TreeMaps can be created with a Comparator.

    If you create your a class you wish to be sortable you should implement the Comparable interface.

提交回复
热议问题