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