I am trying below code but getting error
String x = \"aaa XXX bbb\"; String replace = \"XXX\"; String y = \"xy$z\"; String z=y.replaceAll(\"$\",
Use replace() instead, which doesn't use regular expressions, since you don't need them at all:
String x = "aaa XXX bbb"; String replace = "XXX"; String y = "xy$z"; x = x.replace(replace, y); System.out.println(x);
This will print aaa xy$z bbb, as expected.
aaa xy$z bbb