Reputation: 289
I am trying to execute code if a spot in my String array is equal to a String value I pass in. I know my array is storing the correct values and the method is obtaining the correct value threw the param (I made sure). When the param value matches a value in the array, the if statement nevers gets hit. Below is my code
public void checkWordForLetter(String c)
{
int letterSpotIndex = 0;
int spotNumber = 1;
for(int i = 0; i < (wordLetters.length); i ++)
{
System.out.println(wordLetters[i]);
if(wordLetters[i].equals(c))
{
System.out.println("Letter being looked at in array is: " + c);
letterSpot[letterSpotIndex] = spotNumber;
letterSpotIndex = letterSpotIndex + 1;
spotNumber = spotNumber + 1;
}
}
}
Upvotes: 1
Views: 88
Reputation: 21004
if a spot in my String array is equal to a String value I pass in
I believe you want to use contains
instead of equals
.
If I misunderstood this statement, and you really want to use equals then perhaps you want to compare using toLowerCase()
on each side.
It's hard to tell exactly without knowing the array values and received argument.
Upvotes: 2