1)whether object reference and hashcode are equal or not?
2)if it is equl
String s1=new String("ravikumar");
String s2=new String("ravikumar");
if(s1==s2)//here i am getting false y
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
1)whether object reference and hashcode are equal or not?
2)if it is equl
String s1=new String("ravikumar");
String s2=new String("ravikumar");
if(s1==s2)//here i am getting false y
s1 and s2 are different instances of String objects, so s1==s2 must be false
but i am getting the same hashcode for both the objects....
So!
My parents both have the same address. It doesn't mean they are the same person!
Improving the world one idiot at a time!
k...thanku but
i need one confirmation whether object reference and hashcode are same or not
Of course they are not the same. A reference is how a variable can access an object stored in memory. A hashcode is some arbitrary value that the hashcode method returns for a particular object. The following code is a valid but not very useful hashcode method.
public int hashcode() { return 0; }
Improving the world one idiot at a time!
thanku........