I've tried built-in method String#replaceAll() to replace all "$" from my String content. But it's not working.
String ss = "HELLO_$_JAVA";
System.out.println(ss.indexOf("$"));
System.out.println(ss);
ss = ss.replaceAll("$", "");
System.out.println(ss);// 'HELLO__JAVA' is expected
OUTPUT:
6
HELLO_$_JAVA
HELLO_$_JAVA
Expected output:
6
HELLO_$_JAVA
HELLO__JAVA
EDIT: Although Java regular expressions and dollar sign covers the answer, but still my question may be helpful for someone who is facing same problem when using String#replaceAll(). And Difference between String replace() and replaceAll() also may be helpful.
Two possible solution of that question is
ss = ss.replace("$", "");
OR
ss = ss.replaceAll("\\$", "");