String a ="abc";
return (a.substring(1)=="bc");
I tried to print the result of
a.substring(1)
which is also
"bc"
Why the result is false? I think it's true.
String a ="abc";
return (a.substring(1)=="bc");
I tried to print the result of
a.substring(1)
which is also
"bc"
Why the result is false? I think it's true.
==
compares references and the value of primitives (int
, long
etc), use a.substring(1).equals("bc")
instead.
It should be like this:
String s = "abc";
System.out.println(s.substring(1).equals("bc"));