Java string compareTo() Method

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

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



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


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.


The output is