- 1

Which condition are true and why?

String a=“a”; String b=“b”; String c=a+b; String d=“ab”; If(c==d){ System.out.println(1); } Else{ System.out.println(0); }

8th Apr 2020, 10:15 AM
Siddhant Saxena
Siddhant Saxena - avatar
2 odpowiedzi
0
Hello Siddhant Saxena I hope this post helps you to understand what == is really doing and why you should not use it to compare objects like Strings. https://www.sololearn.com/post/171078/?ref=app
8th Apr 2020, 11:13 AM
Denise Roßberg
Denise Roßberg - avatar
0
The answer is 0. coz == operator is not comparing strings. To compare strings Use .equals() method instead == in if. if(c.equals(d))
8th Apr 2020, 10:37 AM
Nitin Gutte
Nitin Gutte - avatar