Description: The Java.lang.String.compareTo () method compares a dictionary of two strings.
The comparison is based on the Unicode value of each character in the string . This string object represents the sequence of characters of the
The argument string represents the sequence of characters that is compared to the dictionary. Description:
1 PackageCom.yiibai;2 3 Importjava.lang.*;4 5 Public classStringdemo {6 7 Public Static voidMain (string[] args) {8 9String str1 = "Tutorials", str2 = "point";Ten One //comparing STR1 and str2 A intretval =Str1.compareto (str2); - - //Prints the return value of the comparison the if(RetVal < 0) { -System.out.println ("STR1 is greater than str2"); - } - + Else if(retval = = 0) { -System.out.println ("str1 is equal to str2"); + } A at Else { -System.out.println ("str1 is less than str2"); - } - } -}
Return value: This method returns the value 0 if the string is a string of equal parameters,
If the string is less than the string parameter in dictionary order, then returns a value less than 0.
If this string is larger than the string parameter in dictionary order then a value greater than 0
Java String.CompareTo () method