which method replace the spaces with underscore in java code example Example: java replace all space with underscore myString = myString.replaceAll(" ", "_")