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

Java 6772240401473421308

Post a Comment

emo-but-icon

item