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