0

Why "==" working differently for strings in java

let's take strings as a ="a" b="b" c=a+b // so it will be "ab" d = "ab" Then why a & d are not equal as per the following code https://code.sololearn.com/cIU375SG6BhG/?ref=app

27th Aug 2022, 5:56 PM
Anand
Anand - avatar
1 Odpowiedź
0
== compare references for strings and objects.. Not the conntents. Use equals() method for comparing content. c, d reference are different so returns false. Try : d = c; now both will have same reference so returns true.. Hope it helps..
29th Aug 2022, 9:18 AM
Jayakrishna 🇮🇳