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