[JAVA Summary] checks whether the strings are equal. java summary strings

Source: Internet
Author: User

[JAVA Summary] checks whether the strings are equal. java summary strings

Public class CompareObject1 {public static void main (String [] args) {String str1 = new String ("java"); String str2 = new String ("java "); string str3 = str2; if (str1 = str2) {System. out. println ("str1 = str2");} else {System. out. println ("str1! = Str2 ");} if (str2 = str3) {System. out. println (" str2 = tr3 ");} else {System. out. println (" str2! = Str3 ") ;}}// the opened Memory nodes are different, so they are not equal. The values must be equal.

 

 

Public class CompareObject2 {public static void main (String [] args) {String str1 = new String ("java"); String str2 = new String ("java "); string str3 = str2; if (str1.equals (str2) {System. out. println ("str1 equals str2");} else {System. out. println ("str1 not equals str2");} if (str2.equals (str3) {System. out. println ("str2 equals tr3");} else {System. out. println ("str2 not equals str3") ;}}// compare whether the string is equal using equals ()

 

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.