I created two String variables and now i compared both variables using '==' operator and printing the results.
Asked
Active
Viewed 313 times
0
-
Does this answer your question? [function of == in println()](https://stackoverflow.com/questions/51335509/function-of-in-println) – Tom Mar 01 '21 at 01:07
-
2Don't ever use `==` to compare two strings in Java. You'll just get confused. Use `string1.equals(string2)` instead. – Robert Harvey Mar 01 '21 at 01:07
-
On another note, things like this become much clearer when you use `printf` instead of `println`. – Robert Harvey Mar 01 '21 at 01:09
-
1Please don't use images when you don't have to. Instead, copy and format the information in the image as text. – Stephen C Mar 01 '21 at 01:10
-
Hint: Operator Precedence, see https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html, use `()` – Horst Walter Mar 01 '21 at 01:11
-
please consider [Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/q/285551/15244370) – Mar 01 '21 at 01:19
1 Answers
6
In the first case you are comparing
("s1 == s2 is:" + s1) == s2

loop
- 825
- 6
- 15
-
3in other words, probably original should be (corrected) `"s1 == s2 is:" + (s1 == s2)` – Mar 01 '21 at 01:16