What does this code mean?
if( item.compareTo(root.element) < 0 ){
}
I read that:
“Compares two strings lexicographically. Returns an integer indicating
whether this string is greater than (result is > 0), equal to (result
is = 0), or less than (result is < 0) the argument.”
But I don’t don’t get it. Can someone explain with an example please?
Take a look at the documentation of the
Comparableinterface, which defines thecompareTo()method in the first place. The implementation of this interface inStringfollows the same conventions:This means: if the current string is less than the string received as parameter (under the lexicographical order) return a negative integer value. If the current string is greater than the string received as parameter, return a positive integer value. Otherwise, the strings are equal and
0is returned.