public static boolean isHello(String s) {
if (s == "hello") {
return true;
}
return false;
}What is wrong with this method?
- A
The if-statement is missing braces
- B
The method should return s instead of true
- C
Nothing is wrong; it works correctly for all inputs
- Dcheck_circle
Strings should be compared with .equals, not ==
Explanation
== compares object references for Strings, not contents. Use s.equals("hello") to compare characters; == may succeed for literals due to interning but fails generally.