Skip to main content
Java Bug Hunt Medium +20 XP

String Equality Bug

This always returns false for matching strings.

JavaFind the bug
1public boolean isMatch(String input) {
2 String target = new String("hello");
3 return input == target;
4}
The bug is on line 3

Select the correct fix

Show answer and explanation

Answer: Use input.equals(target)

== compares object references, not values. Use .equals() to compare String content in Java.

Hint: == checks references, not content.

What this challenge tests

Bug Hunt in Java: strings, equality.

Related challenges