ICSE Class 10 Computer Applications Question 9 of 46

String Handling — Question 9

Back to all questions
9
Question

Question 2(viii)

Mention the purpose and syntax of compareToIgnore() method.

Answer

The compareToIgnore() method compares two strings lexicographically, ignoring case differences in the strings. It returns a value based on the following logic:

  1. if string1 > string2 the result will be a positive integer, i.e., result > 0
  2. if string1 < string2 the result will be a negative integer, i.e., result < 0
  3. if string1 = string2 the result will be 0, i.e., result = 0

Syntax:
string1.compareToIgnore(string2)