On Jul 20, 5:32 pm, Rohit Bansal <[email protected]> wrote:
> Let I had following code snippet,
> String s1="Hello";
> String s2=s1;
> System.out.println((s1==s2)+" "+ s1==s2);
>
> OUTPUT: false
>
> Query: I need understanding of output...its strange for sure but true;
When you use == for String, you state that the Strings have the same
contents AND the same reference.
Here contents are the same, but references are not.
If you want to compare contents, use equals method.
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---