8:16 am - Sunday October 21, 2018

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

CANDID INDUSTRIAL TRAINING -- CHENNAI
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";

       System.out.println("String:"+s1+"\n");

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

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

      }

 }


Output

          String:String Handling Functions

          Replaced String is:String Handling Functions

Description:

                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.