This example will show how to trim whitespace from a given String using java, guava, apache commons and springframework. This snippets below will trim leading spaces as well as trimming trailing spaces from a String.
Straight up Java
This snippet will show how to trim a string by using the String.trim. By calling the trim function it will remove any leading and trailing whitespace then returning that String.
Guava's CharMatcher.WHITESPACE will determine if any character is whitespace and then calling the .trimFrom will omit any of those characters.
Apache commons StringUtils.trim will removes control characters (char <= 32) from both ends of this String.
Spring's string utility will also handle trim leading and trailing whitespace from the given String.