IGNORE ME!!!
S
sparkfizt
@sparkfizt
0
Reputation
2
Posts
18
Profile views
0
Followers
0
Following
Best posts made by sparkfizt
This user hasn't posted anything yet.
Latest posts made by sparkfizt
-
RE: "" != null
@snoofle said:
String s ="hello";
String t = "hello";
if (s == "hello") // false
if (t == s) // false
if (s.equals(t)) // true
if (s.equals("hello")) // trueclooose but actually you're example would confuse you :P all of those should evaluate to true :P
When you define a string at compile time, then java interns it. This means both s and t are references to the same object in memory. For this reason s == t will evaluate true. also, in if(s == "hello") the hello is also a refrence to an interned string. meaning that will also evaluate to true :P
however, if you did
String a = "hel"
String b = "lo"
String c = a + b;
if(s == c) will evaluate false.
it's wierdness like this that makes java strings confusing to newcomers :P