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

What is a Variable? How to Declare and Assign Values to Variables?

Variable:- Variable  is  a named memory  locations, to store, some value. The  name  of  variable  can  be   chosen  by the  programmer...

Implementing a Java Program?

Implementation of a  java  application  program involves  series of  steps. They  include 1.    Creating  ...

A Simple Java program?

class Sample public  static void main (String args[] ) {   System . out .println (“ java  is better  than  c++); } Class  declaration: The first&nb...

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