0
Can anyone explain why this outputs "true"?
String name = "h"; name += 1; System.out.println(name.equals("h1"));
4 Réponses
+ 8
"h" + 1 results in "h1". So, the output is true.
+ 2
Because, name is string type. And using + operator with string. It will append new value at end of string. when you add 1 to name it become h1. So, it is true
+ 1
java converts
String + int/double/char/long/float
to newString
0
oh, I thought I had gotten a different output when I checked the string before. Thanks guys.