How to replace a String in java which contains dot?

escape the dot, or else it will match any character. This escaping is necessary, because replaceAll() treats the first paramter as a regular expression.

customerName = customerName.replaceAll("\\.", "");

You can do the whole thing with one statement:

customerName = customerName.replaceAll("[\\s.]", "");

Leave a Comment