+ 13
Why the responses are different?
String str1 = new String("some"); String str2 = "some"; System.out.println(str1 == str2); System.out.println(str1.equals(str2));
2 ответов
+ 12
because of the object instance. In the str1, we instantiate a new object of type String. The reference of second one, reference to another instance. So, in the first sout, we compare the instance obj, and get false since they are different. In the second sout, we get true since we compare the values of these two objects.
Take care and think twice when you have to write comparison ;)
+ 2
For strings alway use .equals method is recomend on Android docs