12:51 pm - Tuesday September 25, 2018

StringBuilder Example Program for insert(int dstOffset, CharSequence s, int start,int end)

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
/**
*@author :CandidJava.com
*@descriptions : This program explains the function and use of method insert(int dstOffset, CharSequence s, int start, int end) to insert the character sequence (with start and end location of that char seq) at the place of given Offset in Stringbuilder value s1
*/
public class StringInsert
{
public static void main(String ar[]) throws Exception
{
StringBuilder s1=new StringBuilder("Hello");
                                                                        // object created for string builder with content ?Hello?
char[] c=new char[10];                               // char array created with size 10
c[0]='-';
c[1]='-';
c[2]='B';
c[3]='u';
c[4]='i';
c[5]='l';
c[6]='d';
c[7]='e';
c[8]='r';                                    // values assigned to char location
System.out.println("Before inserted:"+s1);
s1=s1.insert(5, c, 1,8);
System.out.println("After inserted:"+s1);
}
}

OUTPUT:
Before inserted: Hello
After inserted: Hello-Builder

BACK

Filed in: Z-A All Java Codes

Comments are closed.