i already found similar topics but they were not really helpful.
I basically need to know how I can remove whitespaces ONLY at the end of a string.
For example: String a = "Good Morning it is a nice day ";
Should be: String a = "Good Morning it is a nice day";
You see there are like three whitespaces at the end or something. I got replaceAll() as a suggestion but as I said I only want to remove the remaining whitespaces at the end. How do I do that ? I already tried different things like going through the String like this:
for(int i = a.length(); i > a.length() - 3; i++){
if(a.charAt(i) == ' '){
<insert Solution here>
}
}
With the code above I wanted to check the last three Chars of the string because it is sufficient. It is sufficient for the stuff I want to do. There wont be a case with 99+ whitespaces at the end (probably).
But as you see I still dont know which method to use or if this is actually the right way.
Any suggestions please ?