0

I really need help fixing this line of my code, I keep getting these two errors:

First Error: array required, but String found if(x.length() == 0 && y.length() > 0 && y[0] == "*")

Second Error: no suitable method found for replace(int,int) String newY = y.replace(0,1); any help would be appreciated

//Second string is empty and there is wildCard character
if(y.length() == 0 && wildCard)
{
    return true;
}
if(x.length() == 0 && y.length() > 0 && y[0] == "*")
{
    String newY = y.replace(0,1);
    return match(x, newY, true);
}
4

2 回答 2

3

In

if(x.length() == 0 && y.length() > 0 && y[0] == "*")

The "*" is a String, not a character.

Also, the y[0] does not work with Strings in Java, only arrays. That's likely your problem.

于 2013-03-30T23:01:01.813 回答
3

y[0] is for arrays; use y.charAt(0) for strings instead. Furthermore, compare it with '' (the character), and not with "" another string.

于 2013-03-30T23:05:00.313 回答