I'm guessing that compare(str)
is throwing an error because there is no function named compare()
for the String class.
You could use equals()
or equalsIgnoreCase()
for case-insensitive matching. There's also compareTo()
and compareToIgnoreCase()
which are closer to what you typed. Note that the compareTo methods return an int value.
You can read up on the method descriptions here.
Here's an example using equalsIgnoreCase()
.
boolean match = false;
for (int j = 0; j < mobiles.length; j++)
{
match = mobiles[j].equalsIgnoreCase(str);
if (match)
{
break;
}
}
I've changed the terminating condition on the loop to use the length of the mobiles
array. That way you won't need to change a hard-coded value in the event that you change the length of the array. It may also make the intent of the loop a little clearer.
Also as pointed out by ZouZou, writing match == true
isn't necessary since match is itself a boolean value. This case doesn't seem to require the use of a wrapper class either so you could just declare match
as the primitive type boolean
.