[ANSWERED]String concatenation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

[ANSWERED]String concatenation

String a = "a", b ="b", c="ab"; I know from testing that a+b!=c Any brief answers why it is so?

31st Mar 2017, 6:39 PM
Alex Snaidars
Alex Snaidars - avatar
1 Answer
+ 5
In java String is an object type. != and == it's a reference comparison. Different references reference different objects with the same content. To compare content use method (object1).equals(object2) String is immutable object. When you concatenate strings a new string object is built.
31st Mar 2017, 9:13 PM
Alexey
Alexey - avatar