how to remove spaces in the middle of a string in java code example Example: remove space string java a = a.replaceAll("\\s+", "");