Java : Remove all occurrences of char from string

So if you wish to remove all occurences of a certain char from a string you just need to use the String in-built function  – replace(char,emptyChar).

For example, I wish to replace all occurences of ‘:’ from

String str = “bc:14:01:b0:3a:b8”;

To do so I replace the char ‘:’ with the empty one “” like this:

str = str.replace(“:”, “”);

And I get the desired output:


Yup, Is this simple ;).