string remove spaces at the end code example
Example 1: java 8 remove spaces from string
a.replaceAll("\\s+","");
Example 2: regular expression remove spaces
trim unnecessary whitespace
a.replaceAll("\\s+","");
trim unnecessary whitespace