Example & Tutorial understanding programming in easy ways.

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 →
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!