Chapter 2: Determine whether the strings are equal and Chapter 2: Determine whether the strings are equal

Source: Internet
Author: User

Chapter 2: Determine whether the strings are equal and Chapter 2: Determine whether the strings are equal

When comparing string objects, you cannot simply use the comparison operator "=", because the comparison operator compares the addresses of the two strings to see if they are the same. Even if the two strings have the same content, the memory addresses of the two objects are different.

:

String tom = new String ("I am a student"); String jerry = new String ("I am a student"); boolean B = (tom = jerry ); in this case, the value of Boolean variable B is false. Because the string is an object and tom and jerry are references, to compare whether the content of the two strings is equal, use the equals () method and equalsIgnoreCase () method str. equals (String otherstr) // case sensitive str. repeated signorecase (String otherstr) // case insensitive

:

Note: there is a space before equal and a space behind equal.

 

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.