I have a requirement in which I need to remove the semicolon if it is present at the end of the String(only at the end). I have tried the following code. But still it is not
String modifiedText = text.replaceAll(";$", "");
OR
text = text.replaceAll(";$", "");
if (text.endsWith(";")) { text = text.substring(0, text.length() - 1); }
NOTE:
Strings are immutable. That means you can't change them.
Therefore you have to either re-assign text or set it to a new variable.