Bird
0
0

What will be the output of this code snippet?

medium📝 Predict Output Q5 of 15
Java - Strings and String Handling
What will be the output of this code snippet?
String a = "Test";
String b = "test";
System.out.println(a.equals(b));
System.out.println(a.equalsIgnoreCase(b));
Afalse true
Btrue false
Ctrue true
Dfalse false
Step-by-Step Solution
Solution:
  1. Step 1: Check equals() behavior

    equals() is case-sensitive, so "Test" equals "test" returns false.
  2. Step 2: Check equalsIgnoreCase() behavior

    equalsIgnoreCase() ignores case, so it returns true for these strings.
  3. Final Answer:

    false true -> Option A
  4. Quick Check:

    equals() case-sensitive, equalsIgnoreCase() ignores case = false true [OK]
Quick Trick: equals() is case-sensitive; equalsIgnoreCase() ignores case [OK]
Common Mistakes:
  • Expecting equals() to ignore case
  • Mixing up output order
  • Using == instead of equals()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes