+ 1
What is the meaning in following java code: String s1="hello"; String s2="hello";boolean c=s1.equals(s2); System.out.println(c);
4 ответов
+ 2
== it compares objects references( reference means memory location), the both objects are in different location in memory so when u compare these objects with ==, it returns false, because these sind different objects, altough these contain same string :), i hope, i can help u.
+ 2
s1 == s2 is a true or false evaluation. It's like asking "is the reference at s1 equal to the reference at s2?" . The answer would be false, since they occupy different addresses in memory. If you want to see if two strings hold the same values use s1.equals(s2) as your evaluation.
+ 1
what does mean by following code:
System.out.println(s1==s2):
0
hi, there are two objects,(because string is object). U wanna compare the two objects, so u need compare,both of the objects are same so, it should be returned treu :)i hope, i can help u