In Java, the String class implements Comparable, which means that the String objects are fully ordered. This ordering is called the natural ordering of the class, and the class method compareTois called its natural method of comparison. The set of String objects is also countable in the mathematical sense.
I need a function that takes a string and returns the next one according to the natural ordering of the strings.
For mathematically inclined,
function(X) = Y, where Y is such that: 1) X < Y
2) for all Z, if X < Z, then Y <= Z.
Can you think of a function that does this for strings? (Those that match ^[A-Za-z0-9]+$. I don't care, but you can escape control characters or anything that can cause headaches with encodings is illegal in XML, has line breaks or similar "problematic" characters.)
source
share