Replace particular character with other in a String JAVA

simple java program to replace particular character in a string with other.

class replaceProgram{
    public static void main(String args[])  {

String st1=”TechieTet”;
String st2=st1.replace(‘e’,’x’);
System.out.println(st2);
}
}

Output of this program will be

  Txchix Txt

 

Syntax of replace method

    replace(char oldchar, char newchar)

   replace(string oldstr, string newstr)

Not only character also a part of string i.e substring can be changed using replace.