remove space java code example Example 1: java 8 remove spaces from string a.replaceAll("\\s+",""); Example 2: remove space string java a = a.replaceAll("\\s+", "");