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

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

Here we write a method that will remove given character from the String,for the use of charToBeRemoved () method .by  the use of this method we remove the any  character in a string.

example: 

public class Removetest{

public static void main (String [] h) {

System.out.println (Chartoremove ("My name is alok sharma", 'a')); }

public static String Chartoremove(String string, char charToBeRemoved) {

if (string == null)

return "";

StringBuilder strBuild = new StringBuilder ();

for (int i = 0; i < string.length (); i++) {

char ch = string.charAt (i);

if (ch == charToBeRemoved)

continue;

strBuild.append (ch);}

return strBuild.toString ();}}

Read More →