how to create your own method in java where you remove spaces code example Example: remove space string java a = a.replaceAll("\\s+", "");