why the output is like this? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

why the output is like this?

public class rev { public static void main (String[] args){ String s1 = "hello"; String s2 = "hel" + "lo"; String s3 = " mum"; if(s1==s2){ System.out.println("1.same"); }else{ System.out.println("1.different"); } if(s1 + s3 == "hello mum"){ System.out.println("2.same"); } else{ System.out.print("2.different"); } } } #output: 1.same 2.different

3rd Feb 2018, 11:57 AM
mariam_sanad
mariam_sanad - avatar
2 Answers
3rd Feb 2018, 1:53 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 1
For comparing Strings, you should use .equals instead of ==.
3rd Feb 2018, 1:40 PM
Jonas Schröter
Jonas Schröter - avatar