I have problem with default comparator for Strings (in SortedSet). The problem is that default comparator doesn’t sort good String that contains numbers i.e.:
In set i have:
room1, room2, room100
Natural ordering should be like above but in set I have:
room1, room100, room2
I know why it is but I don’t know how to change it.
Try this comparator, which removes all non-digit characters then compares the remaining characters as numbers:
When this code is run:
This is the output:
When the numbers are decimals, retain both digits and dots.
When this code (which shows use of a function instead of an anonymous class) is run:
This is the output: