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

Why is Java known as Plat Form Neutral Language?

The goal of Java is “write once run anywhere, any time, forever”. So Java is not dependent on any platform. It creates byte code, this code supports to all platforms. So Java is known as p...

How is Java more Secured than Other Languages?

Everything that you download form internet, you are risking a viral infection. Prior to Java, most users did not download executable programs frequently, and those who did scan them for virus prior ...

Explain Web Browsers?

1) Web browsers are used to navigate through the information found on the net. 2) Web browser is a software program to view (Or) run HTML files. ...

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