I am trying to remove the last character from a string, if it is a /. I am using a string array, temp[], to store the strings.
Here’s my code:
char ch = ' ';
for (int st = 0; st < temp.length; st++)
{
ch = temp[st].charAt(temp[st].length()-1);
if (ch == '/')
temp[st] = temp[st].substring(0, temp[st].length()-1);
result2.append(temp[st]);
}
but i am getting
StringIndexOutOfBoundsException -1
What am I doing wrong?
If you have empty String
""thentemp[st].length()-1 == -1