I have a StringBuilder object that needs to be trimmed (i.e. all whitespace chars /u0020 and below removed from either end).
I can\'t seem to find a method in string
I had exactly your question at first, however, after 5-minute's second thought, I realized actually you never need to trim the StringBuffer! You only need to trim the string you append into the StringBuffer.
If you want to trim an initial StringBuffer, you can do this:
StringBuffer sb = new StringBuffer(initialStr.trim());
If you want to trim StringBuffer on-the-fly, you can do this during append:
Sb.append(addOnStr.trim());