PROGRAM
public static void main(String args[]) {
String s1 = new String("jjj");
String s2 = "jjj";
String s3 = new String("jjj");
System.out.println("== ");
System.out.println(s1 == s2);
System.out.println(s2 == s3);
System.out.println(s1 == s3);
test(s2);
System.out.println(".equals");
System.out.println(s1.equals(s2));
System.out.println(s2.equals(s3));
System.out.println(s1.equals(s3));
}
static void test(String X) {
String Y = new String("jjj").intern();
System.out.println(X.equals(Y));
}
OUTPUT
==
false
false
false
true
.equals
true
true
true
No comments:
Post a Comment