String line = "Pritom K Mondal"; line = line.replaceAll("(?s).", "X"); Will output: XXXXXXXXXXXXXXX
(?s)
DOTALL