1 public class StringBuffer {
5 // private static final int DEFAULTSIZE=16;
7 public StringBuffer(String str) {
8 value=new char[str.count+16];//16 is DEFAULTSIZE
11 for(int i=0;i<count;i++)
12 value[i]=str.value[i+str.offset];
15 public StringBuffer() {
16 value=new char[16];//16 is DEFAULTSIZE
25 public int capacity() {
29 public char charAt(int x) {
30 return value[x+offset];
33 public void append(String s) {
34 if ((s.count+count+offset)>value.length) {
36 char newvalue[]=new char[s.count+count+16]; //16 is DEFAULTSIZE
37 for(int i=0;i<count;i++)
38 newvalue[i]=value[i+offset];
39 for(int i=0;i<s.count;i++)
40 newvalue[i+count]=s.value[i+s.offset];
45 for(int i=0;i<s.count;i++) {
46 value[i+count+offset]=s.value[i+s.offset];
52 public void append(StringBuffer s) {
53 if ((s.count+count+offset)>value.length) {
55 char newvalue[]=new char[s.count+count+16]; //16 is DEFAULTSIZE
56 for(int i=0;i<count;i++)
57 newvalue[i]=value[i+offset];
58 for(int i=0;i<s.count;i++)
59 newvalue[i+count]=s.value[i+s.offset];
64 for(int i=0;i<s.count;i++) {
65 value[i+count+offset]=s.value[i+s.offset];
71 public String toString() {
72 return new String(this);