insert(offset, x) in JAVA – JAVA 10th Class notes – ICSE JAVA Notes

insert(offset, x) in JAVA – JAVA 10th Class notes – ICSE JAVA Notes

insert(offset, x) :

insert(offset, x) function allows you to insert a String at the specified index into the another String.

Syntax : str1.insert(index, str2);

Example : StringBuffer str1 = new StringBuffer(“COMPUTER FUN”);

StringBuffer str2 = new StringBuffer(“ IS”);

str1.insert(8,str2);

 

Output : COMPUTER IS FUN

 

/* Program to illustrate the function insert() */

 

class Insert

{

public static void main(String args[])

{

StringBuffer str1= new StringBuffer(“COMPUTER FUN”);

System.out.println(” String : ” + str1);

StringBuffer str2= new StringBuffer(” IS”);

System.out.println(” String to be Inserted : ” + str2);

str1.insert(8,str2);

System.out.println(” String After Inserting : ” + str1);

}

}

mso-bo8!-on e id black .5pt;mso-border-top-themecolor: text1;mso-border-alt:solid black .5pt;mso-border-themecolor:text1;padding: 0in 5.4pt 0in 5.4pt;height:.3in’>

setCharAt(index,c)

delete(beg, end)

setLength(n)

reverse( )

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Security Code: