[ANSWERED]String concatenation | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula gr√°tis
+ 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 Resposta
+ 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 - avatar