"Java Summary" string comparisons are equal

Source: Internet
Author: User

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 open memory nodes are different, so they are not equal; the assignment must be equal.

 Public classCompareObject2 { Public Static voidMain (string[] args) {String str1=NewString ("Java"); String str2=NewString ("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 strings for equality with equals ()

"Java Summary" string comparisons are 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.