String buffer class in Java?

String buffer class:

String buffer is a peer class of string. While string creates strings of fixed length, string buffer creates strings of flexible length that can be modified in terms of both length and content. We can insert characters and sub strings in the middle of a string, or opened another string to the end as below list some of the methods that are frequently used in string manipulations.

Commonly used stringBuffer methods:

Method
Task
S1.setcharat(n, ‘x’)
S1.append(s2)
S1.insert(n, s2)

S1.setlength(n)
Modifies the nth character to x
Appends the string s2 to s1 at the end
Inserts the string s2 at the position n of the string s1
Sets the length of the string s1 ton. If n
If n>s1.length ( ) zeros are added to s1

class StringManipulation
{
public static void main(String args[ ] )
{
StringBuffer str=new SringBuffer(“object language”);
System.out.println(“original string:”+str);
System.out.println(“length of string:”+str.length);
for (int i=0; i ;  i < str.length(  ) ; i++)
{
int p=i+1;
System.out,.println(“character at position”+p+”is”+str charAt(i));
}
String astring=new string(str.asting ( ));
int pass=astring .indexOf(“language”);
Str.insert(pas, “oriented”);
System.out.println(“modified string”+str);
Str.oppend(“improve security”);
System.out.println(“appended string”+str);
}
}

Related

Differences Between Applets and Standalone Programs?

Differences  Between   Applets  and   stand alone  programs : Although  both  the  applets   is  stand  alone  applicati...

How to Design a Web Page?

Designing  a   web  page  : Java  applets  are  program  that  reside  one  web page.  In  order  to r...

Finalizer Method in Java

FINALIZER METHODS: We have seen that a constructor method is used to initialize an object when it is declared. This process is known as initialization. similarly,java supports a concept called fi...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item