How are these 2 strings different ..? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

How are these 2 strings different ..?

a substring containing​ all elements of the original string is created but these are not equal., how...? https://code.sololearn.com/c9snOqooORdn/?ref=app

14th Aug 2017, 11:02 PM
Uri vath
Uri vath - avatar
1 Réponse
+ 1
because == checks if the variables references the same object, not wether their data are equal. lets say string x = "hello" and string t = "hello". == will return false because the two strings are different instances on the memory and the variables reference two different addresses. but if you set string t = x then == will return true. think of variables as names and object as a person. if a person has nicknames, doesn't matter what nicknames are, they all refer to the same person. if like say a person has an identical twins, and you use their names to compare the two, each name refers to different person even if they look identical
14th Aug 2017, 11:08 PM
Gao Xiangshuai
Gao Xiangshuai - avatar