Questions like this discuss the limitations to the logic used by the String::trim
method. Some libraries such as Guava offer alternatives.
I vaguely recall that a recent version of Java (8, 9, 10) shipped with an alternative, a more modern Unicode-savvy approach to defining and removing whitespace characters from text.
Is there such a facility bundled with Java now?