In this particular case it does not matter, but you really should use replace
instead of replaceAll
:
text = text.replace(subtext, "");
The replaceAll
method uses regular expressions, and some characters have special meaning.
In this particular case you won't see any difference because there must be something subtly different in subtext
, so it cannot be found in text
. Perhaps there's extra white space or the line break character is encoded differently. It's very hard to see differences in white space looking at output produced by System.out.println
.