Java String.CompareTo () method

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.