0
Using == operatorwill the following be correct?
I know when use the == operator to compare 2 reference variable is used to see if they point to the same object, address. Will this code generate true? or is even allowed to to check if the reference object points to the same address of the string literal?String myName = "Bob";if (myName == "Bob"){ //do something }
3 Answers
+ 3
u can use method "equals" to compare values of strings. operator == compare addresses of variables
+ 1
Yes that code equals true
+ 1
the code will run however we will be looking at a logic error, I had to refresh my mind. the rational operator == should not be used when comparing strings.