I have a TreeTable and would like to perform the sort by number and alphabetically when clicking on header.
Example:
- On a first click, I have to check that the column content is sorted by number
- If I click on another column that contains
Stringdata, I have to check that column content is sorted alphabetically.
Are there known functions that could I use?
I’ve used Collections for sorting number , but how do I can make the sort alphabetically ?
Collections.sor(myList) is OK for sorting by number but I would sort data alphabetically.
thanks
This can easily be done via
Collections.sort(...). Create a copy of your list, sort it and check if they are equal.Example:
This can be done, if the elements in the list are comparable (i.e. are of type
T implements Comparable <T>). Strings are comparable, and their default comparator sorts them alphabetically (though upper-case are always comes before lower-case)You may also provide a
Comparatorfor a more flexible sorting.Here is a more complicated example.
This will print us
[Abaddon, Antichrist, abyss, armageddon]. This is because default comparation is case-sensitive. Lets fix it:This one prints
[Abaddon, abyss, Antichrist, armageddon].Now you may worship Satan in strict alphabetical order.
See also