Q. How would you compare two strings for equality, ignoring their case?

A
str1 == str2
B
str1.equals(str2)
C
str1.equalsIgnoreCase(str2)
D
str1.matches(str2)
Solution:

The equalsIgnoreCase() method compares two strings lexicographically, ignoring case differences. Using == checks for reference equality (if they are the same object), not value equality.

Entri Contact Image

Get Expert Advice for Free: Register for Your Free Consultation Now!