Java Instance – string comparison

Source: Internet
Author: User

Package string;

public class Equals {

public static void Main (string[] args) {
/**
* using "=" to compare two strings, is to compare the "address" of two objects is consistent,
* The essence is to determine whether two variables point to the same object, and if so, return True,
* Otherwise the return is false. The Equals method of the string class is to compare the contents of the two strings in a consistent way
*/
String str1 = "pig chubby";
String str2 = "pig chubby";
System.out.println (str1 = = str2);//return True
System.out.println (Str2.equals (STR2));//return True
String str3 = new String ("fat");
String STR4 = new String ("fat");
System.out.println (STR3 = = STR4);//return False
System.out.println (Str3.equals (STR4));//return True

}

}

Java Instance – string comparison

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.