String buffer class in Java?
https://www.computersprofessor.com/2017/01/string-buffer-class-in-java.html
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:
|
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);
}
}