Java checks whether two strings are equal

Source: Internet
Author: User

I just learned Java In today's programming, there is a tricky problem, that is, the question of determining whether two strings are equal. In programming, the expression that compares two strings is usually" = " , However Java . In Java Is used Equals ();

Example:String and BComparison with string:

If (A. Equals (B )){

}

ReturnTrueOrFalse.

string equals the method is used to compare whether two strings are equal. Because the string is of the object type, you cannot use the simple " = . equals compare whether the content of the two objects is equal.

Note:

Equals () Compare the content of an object (case-sensitive Letter format), but if you use = When two objects are compared, the memory addresses of the two objects are compared, so they are not equal. Even if the content is equal, the memory addresses of different objects are also different.

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.