I'm trying to compare an index from my array of char's to a string, I'm using the .equals method but I'm running into errors. Any help?
if (j[1].equals("A"))
{j[1] = 10;}
I keep getting this error:
int cannot be dereferenced
else if (j[1].equals("A"))
Try this instead:
if (j[1] == 'A')
If the j array contains chars, then you must compare its values with another char, not a String (even if the string has length 1) - they're different data types. And because a char is a primitive type, == is used for equality comparisons.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With