S. Nary S. Nary - 1 month ago 19
Java Question

Is there an opposite method for .charAt()?

The remove.charAt() does not seem to work so I was wondering if there was something, where I input an int and it tells me what character is at that point?
Again if anyone has any ideas it would be greatly appreciated. :-)

public static String removeYak(String remove)
{
String fina1 = "";
for(int y = 0; y < remove.length(); y++)
{
if(remove.toLowerCase().charAt(y) == "y")
{
if(remove.toLowerCase().charAt(y+1) == "a")
{
if(remove.toLowerCase().charAt(y+2) == "k")
{
fina1 = str.substring(k+1);

}
}
}
}
return fina1;
}

Answer

No, there isn't. However, you're using a correct method. The problem is in your if's. When you do something like:

String string = "abc";
char c = string.charAt(2);

You must compare character to a character, not to a string. In your if's, you write things like remove.toLowerCase().charAt(y) == "y", however, what you're looking for is remove.toLowerCase().charAt(y) == 'y'. Notice the apostrophe by the y you must use.