Public Class Compaare { /*** == Different from Equals ()* /Public Static Void Main (String [] ARGS) {String S1 = New String ("Hello, World!"); // Create two String object objects Quote; String S2 = New String ("Hello, World!"); String S3 = S1; // Reference the S1 object to the S3 System.out.println ("S2 == S3's calculation results are:" + (s2 = = s3); // The address is different. (S3) The operation results of the operation are: "+(s2.equals (s3))); // The content is the same}} The operation result of S2 == S3 is: false
The operation result of S1 == S3 is: true
The calculation results of S2.equals (s3) are: true
Summarize:
== Compared with Equals (), the content is different. Whether the address is equal. Because S1 and S2 are two different object references, the positions of the two in memory are different, and the String S3 = S1 statement is given the reference of S1 to S3, so the two objects of S1 and S3 are equal.