1 / 5

String Buffer Class

String Buffer Class. An object of String buffer represents mutable sequence of character. Constructor:- Public StringBuffer (); Public StringBuffer ( int capacity); Public StringBuffer (String s); E.g. stringBuffer s=new StringBuffer (); StringBuffer t=new StringBuffer (10);

maree
Télécharger la présentation

String Buffer Class

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. String Buffer Class An object of String buffer represents mutable sequence of character. Constructor:- Public StringBuffer(); Public StringBuffer(int capacity); Public StringBuffer(String s); E.g. stringBuffer s=new StringBuffer(); StringBuffer t=new StringBuffer(10); StringBuffer u=new StringBuffer(“ABC”);

  2. Each StringBuffer Object has a initial capacity that represents maximum number of characters that can be stored in the stringBuffer object without changing its size. • Capacity of a stringBuffer object can be found with the help of capacity method . • Public int capacity(); • S.O.P(s.capacity()); 16 • S.O.P(t.capacity()); 10 • S.O.P(u.capacity()); 19 • Default capacity of a string Buffer object is 16.

  3. Methods of string Class :- • Append():- is used at the contents of a string at the end of invoking string buffer Object. • Public StringBuffer append(String s); • StringBuffer s= new StringBuffer(“ABC”); • StringBuffer t=s.append(“DEF”); • S.o.P(s);//ABCDEF • S.O.p(t);//ABCDEF • S.o.p(s==t); True NOTE:returns of S.B. class that changes the contents of S.B. Object returns the reference of invoking object so that method cal can be chain.

  4. Ex:StringBuffer s=new StringBuffer(“ABC”); • S.append(“ABC”).insert(3,”PQR”); • s.insert(3,”PQR”); • insert():- • It is used to insert a string at the specified position in a stringBuffer object. • Public StringBuffer insert(int index, String s); • replace():-it is used contents at the specified index from the specified string . • Public StringBuffer replace(int start index, int end index; string s);

  5. Stringbuffer a=new StringBuffer(“abc”); • a.append(“pqr”).insert(2,”xyz”);//abcpqr&abxyzcpqr • replace(0,1,”mno”); //mnobxyzcpqr • Reverse():- • Public stringBuffer reverse(); • toString():- public String toString();

More Related