How to remove duplicated special char in Java? [closed]

i have String in java: “[email protected]}Cl~Aa@pO}[email protected]|TkJjSoW|[email protected]}[email protected]_@j[email protected]{[email protected][email protected]{\t][email protected]@[email protected]

And i would like to change all duplicates “\” to one “”.

Replace function does not work on special characters 🙁 How can i do that?


I think replace("\\", "\") should replace all backlashes:

String input = "[email protected]}[email protected]}[email protected]|TkJjSoW|[email protected]}[email protected][email protected]@{[email protected][email protected]{\\t][email protected]@[email protected]\\";
System.out.println("input: " + input);
String replaced = input.replace("\\", "\");

Above code prints the following output: