Search code examples
javastringcompareto

Minimum string as per String#CompareTo


Ok, I'm sure that this must exist on here somewhere, but I can't seem to find it.

Is there, and if there is what is, a minimum (non-null) String sequence according to String#CompareTo?

I'm guessing "" but I'm not entirely sure.


Solution

  • Given the implementation of String#compareTo (see source) you can verify that a string of size 0 (thus the empty string) will always be inferior or equal to any other non null string. (equal in case of comparing to the empty string).