I have a string like this:
mysz = \"name=john age=13 year=2001\";
I want to remove the whitespaces in the string. I tried trim()
The most correct answer to the question is:
String mysz2 = mysz.replaceAll("\\s","");
I just adapted this code from the other answers. I'm posting it because besides being exactly what the question requested, it also demonstrates that the result is returned as a new string, the original string is not modified as some of the answers sort of imply.
(Experienced Java developers might say "of course, you can't actually modify a String", but the target audience for this question may well not know this.)