Question: How can I do it? I made a research but I could not find a clear answer.I tried to use

```
pass = pass.replaceAll("$", "\\$");

```

but It does not work.

Answer: 
use 

```
pass = pass.replace("$", "\\$");

```

It will also replace all occurrences. See [JavaDoc](http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#replace%28java.lang.CharSequence,%20java.lang.CharSequence%29).

If you prefer the hard way and want to use a regex, you need:

```
pass = pass.replaceAll("\\$", "\\\\\\$");

```

This can be simplified with `Matcher.quoteReplacement()` but still, only use `replaceAll()` when you need to replace something that matches a regular expression, and use `replace()` when you have to replace a literal sequence.
The problem is that [`String.replaceAll`](http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#replaceAll%28java.lang.String,%20java.lang.String%29) uses regular expressions, where both `\` and `$` have special meanings. You don't want that as far as I can tell - you just want to replace the strings verbatim. As such, you should use [`String.replace`](http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#replace%28java.lang.CharSequence,%20java.lang.CharSequence%29):

```
pass = pass.replace("$", "\\$");

```

(Personally I think the fact that `replaceAll` uses regular expressions is a design mistake, but that's another matter.)