public class StringComparison
{
public static void main( String [] args)
{
String s1 = "Arsalan";
String s2 = new String("Arsalan");
String s3 = new String ("Arsalan");
if ( s1 == s2 )
System.out.println (" S1 and S2 Both are equal...");
else
System.out.println ("S1 and S2 not equal");
if ( s1 == s3 )
System.out.println (" S1 and S3 Both are equal...");
else
System.out.println (" S1 and S3 are not equal");
if ( s2 == s3 )
System.out.println (" S2 and S3 Both are equal...");
else
System.out.println (" S2 and S3 are not equal");
}
}
If you run this, you can see that S2 and S3 are also not equal. This is because s2, s3 are references to a String Object and hence they contain different address values.