I am trying below code but getting error
String x = \"aaa XXX bbb\"; String replace = \"XXX\"; String y = \"xy$z\"; String z=y.replaceAll(\"$\",
If the replacement string includes a dollar sign or a backslash character, you should use
Matcher.quoteReplacement()
So change
String z=y.replaceAll("$", "\\$");`
to
String z = Matcher.quoteReplacement(y);