0 votes
in JAVA by

Write a method that will remove given character from the String?

1 Answer

0 votes
by
We can use replaceAll method to replace all the occurance of a String with another String. The important point to note is that it accepts String as argument, so we will use Character class to create String and use it to replace all the characters with empty String.

    private static String removeChar(String str, char c) {

        if (str == null)

            return null;

        return str.replaceAll(Character.toString(c), "");

    }

Related questions

0 votes
asked Mar 16, 2021 in JAVA by Robindeniel
0 votes
asked Mar 16, 2021 in JAVA by Robindeniel
...