There are two types to use java String.compareTo():

  1. string compare with an object.
    2.compare two string in character order.

Signature

Arguments

  • o --an object to campere with.
  • anotherString -- a string to compare with.

Return

This two methods will return an integer number.First,they compare the character which in given Strings by order,if the first character is not same as the first character of the argument string,the compare process will stop and return length difference of this two string,if the first character is same as the first character of the argument string,than will continue to get their second character to compare to each other,and so on until one of the characters being compared or compared ends.

Example

The output is

Categories: Java