posted Today 1:07:17 PM 0
posted Yesterday 11:17:32 PM private message
0
Quote
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
a==c is true because a and c refers to the same strings in the
string constant pool.
a, b, c, d has the same hashcodes because hashcode of a string is computated in the String class. For example String a = new String("a") ; String a1 = new String("a") ; a and a1 have the same hashcode.
a.equals( b ) is true because a and b have the same string.
But a == b is false because a refers to "Hello1234", but b refers to a string that is concatenated by "Hello" and new String("1234"). This is a new string object created when "Hello" and new String("1234") is concatenated.
Try this:
String a = new String("Hello1234");
String b = new String("Hello1234");
Will a==b be true?
I don't think so. a and b refers to two different string objects.
Try another one:
String a = "Hello1234";
String b = "Hello1234";
Will a == b be true?
Yes. I think so. a and b refers to the same string in the string constant pool.
a== d is false because a refers to a string in the string constant pool "Hello1234" and d refers to a new String object created from the character array.