3:50 pm - Wednesday February 17, 7396

Replace a character with new character String replace(char oldChar,char newChar)

Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

                               This method is used to replace the specified character in the given string. Old character will be replaced by a new character. If the specified character occured number of times in the string then it replace all the occurred places.

Example Program

  public class Replace 

   public static void main(String args[])


       String s1="String Handling Functions";


       String s2=s1.replace('i','l');

       System.out.println("Replaced String is:"+s2);




          String:String Handling Functions

          Replaced String is:String Handling Functions


                In the above program, the specified character i placed number of times in the given string. l is a new character that replace all the character i in the string.

Filed in: Java Examples

Comments are closed.