Just a heads up: This is maybe not as much of a 'help me program' question, but more of an 'is this a bug or just not clearly defined behaviour'.
Let's take the following list of strings:
item01mark2, item10mark2, item10mark03, item1mark3
Intuitively it should (of course) sort to:
item01mark2, item1mark3, item10mark2, item10mark03
Using Java17's standard 'natural' ordering implementation 'Comparator.naturalOrder()', this list sorts to:
item01mark2, item10mark03, item10mark2, item1mark3
After some quick checks, other natural sorting libraries (e.g. Python 'natsort') agree with the intuitive sorting. Would you consider this a bug (worth reporting), or is this just due to the vagueness of the definition of natural string sorting?
Update: Okay, so basically this is just a language-disambiguation thing. I expected something called 'NaturalSorting' to be an implementation of Natural Sorting, which is just isn't. Case closed.
In the case of Java's Comparator.naturalOrder(), it follows the lexicographic order of characters in the string, so it considers "10" as smaller than "2" when comparing the strings. This behavior aligns with how strings are typically sorted as plain text.
On the other hand, libraries like Python's natsort use a more human-friendly interpretation of natural sorting. They attempt to recognize and compare numbers within the strings as actual numeric values, which leads to a different sorting result that matches human expectations more closely.
Whether this is a bug or not largely depends on the specific use case and the expectations of the users. If the goal is to sort strings in a way that matches human intuition, then the behavior of natsort may be preferred. However, if you require strictly lexicographic sorting, Java's Comparator.naturalOrder() behavior would be more appropriate.