how to delete all spaces from a string in java for loop code example Example: java 8 remove spaces from string a.replaceAll("\\s+","");