I am having strings like this \"aaaabbbccccaaffffddcfggghhhh\" and i want to remove repeated characters get a string like this \"abcadcfgh\".
A simplistic implementati
You can do this:
"aaaabbbccccaaffffddcfggghhhh".replaceAll("(.)\\1+","$1");
The regex uses backreference and capturing groups.
The normal regex is (.)\1+ but you've to escape the backslash by another backslash in java.
If you want number of repeated characters:
String test = "aaaabbbccccaaffffddcfggghhhh";
System.out.println(test.length() - test.replaceAll("(.)\\1+","$1").length());
Demo