Try the following:
String test = myst.replace(".", "A");
Difference:
replaceAll()interprets the pattern as a regular expression, replace()interprets it as a string literal.
Here's the corresponding source code from java.lang.String(indented and commented by me):
public String replaceAll(String regex, String replacement) {
return Pattern.compile(regex)
.matcher(this)
.replaceAll(replacement);
}
public String replace(CharSequence target, CharSequence replacement) {
return Pattern.compile(
target.toString(),
Pattern.LITERAL
).matcher(this)
.replaceAll(
Matcher.quoteReplacement(
replacement.toString()
));
}
Reference:
source
share