java remove whitespace before and after string code example
Example 1: how to strip trailing spaces in java
String str = new String(" apples ");
str.trim(); // result is a nes string "apple"
Example 2: remove space string java
a = a.replaceAll("\\s+", "");