class ReplaceStringCharactor
{
public static void main(String args[])
{
String str="apple";
char oldchar='p';
char newchar='b';
int len=str.length();
char[] a=new char[len];
str.getChars(0, len, a, 0);
System.out.println("string before replace :"+str);
int i=0;
while(i<len)
{
if(a[i]==oldchar)
{
a[i]=newchar;
}
i++;
}
System.out.print("String after replace :");
String newstr=new String(a);
System.out.println(newstr);
}
}
Nice concept..
ReplyDelete