Why str1 == str2 return false but str1 == str3 return true? What were you expecting instead?
As Ko Ko Naing mentioned, str1 and str3 refer to the same String object. At compile time, since Strings are immutable (cannot be changed once created)
Java is able to safely arrange a few special things to allow two different String references to actually refer to the same String object when String literals are used. The double equals operator in Java, ==, is used to
test whether two variables refer to the same value. In this case, they do.
Java allows you to specify that no matter if other instances of some String exist, by creating a new String instance with
new String("my string") a new String object will be created at runtime, even though it has the same internal value as some String literal. So, str1 is referring to the String object specified at compile time as a String literal, while str2 is referring to a different String object, and so comparing the two references with == results in false since they aren't referring to the same String object.
Now, str1.equals(str2) would be true, since the two different String objects referred to by str1 and str2 actually represent equal values.
Is this getting any clearer?