Hire QA – Specialized in QA Recruitment, Technical Interviews and Testing Solutions

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

Category: Java

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), “”);
}

Leave a Reply

Your email address will not be published. Required fields are marked *