Enter your E-mail Address below for Free E-mail Alerts right Into your Inbox: -

Thursday

Java Program to Replace a Character with another Character form a String

Java Program to Replace a Character with another Character form a String

public class Sample {

public static String replaceChar(char character,String str,char replaceChar)
{
int l = str.length();
char[] charStr = str.toCharArray();
for(int i=0;i<l;i++)
{
if(charStr[i]==character)
{
charStr[i]=replaceChar;
}
}
return String.valueOf(charStr);
}
    public static void main(String args[])
    {
   System.out.println(replaceChar('a',"malayalam",'b'));
    }
}

No comments:

Post a Comment