The 5th Chapter string determines whether the string is equal

Source: Internet
Author: User

Comparing a String object cannot simply use the comparison operator "= =" because the comparison operator compares the address of a two string . Even if the contents of the two strings are the same, 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); at this point, the value of the Boolean variable B is false, because the string is the object, and Tom, Jerry is the reference therefore, to compare the contents of two strings for equality, you should use the Equals () method and the Equalsignorecase () method Str.equals (String otherstr)/    /Case-sensitive str.equalsignorecase (string otherstr)    //Ignoring case

  

The 5th Chapter string determines whether the string is equal

Related Article

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.