Bird
0
0

Which of the following is the correct syntax to compare two strings s1 and s2 ignoring case in Java?

easy📝 Syntax Q12 of 15
Java - Strings and String Handling
Which of the following is the correct syntax to compare two strings s1 and s2 ignoring case in Java?
As1.compareToIgnoreCase(s2)
Bs1.equals(s2)
Cs1.equalsIgnoreCase(s2)
Ds1 == s2
Step-by-Step Solution
Solution:
  1. Step 1: Identify method to compare strings ignoring case

    Java provides equalsIgnoreCase() to compare strings ignoring letter case differences.
  2. Step 2: Confirm syntax correctness

    s1.equalsIgnoreCase(s2) is the correct method call syntax.
  3. Final Answer:

    s1.equalsIgnoreCase(s2) -> Option C
  4. Quick Check:

    Use equalsIgnoreCase() to ignore case in string comparison [OK]
Quick Trick: Use equalsIgnoreCase() to compare strings ignoring case [OK]
Common Mistakes:
  • Using equals() when ignoring case is needed
  • Using == for string comparison
  • Using non-existent compareToIgnoreCase() method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes