We have a
String s="my name is bob";
System.out.print(s.replace("a","p")); // so here a replace to p
but I want a variable in the place of a
example
char o='a';
system.out.print(s.replace(o,"p"));
But here it is giving an error so how can be put a variable inside a replace method is there any way to do it?
String o="a";system.out.print(s.replace(o,'p'));if you want to replace a singlecharwith a singlechar..replace()has two signatures, one of which isreplace(char,char)and second isreplace(CharSequence, CharSequence)."a"but in your second example you define it aschar.