java program to remove spaces from given string code example Example: java 8 remove spaces from string a.replaceAll("\\s+","");