Computer Applications

The two Java statement are used to check for the equality of the strings "COP" and "cop" are as follows:

"COP".equals("cop") 
"COP".equalsIgnoreCase("cop")

The output of the above statements is:

  1. false, true
  2. true, false
  3. false, false
  4. true, true

Java String Handling

1 Like

Answer

false, true

Reason — In Java:

  • "COP".equals("cop") checks for exact match, including uppercase and lowercase letters. Since "COP" and "cop" are not exactly the same, it returns false.
  • "COP".equalsIgnoreCase("cop") checks for equality by ignoring the case of letters. So it treats "COP" and "cop" as equal and returns true.

Answered By

3 Likes


Related Questions