1 // Test StringBuffer.replace(), reverse(), insert(String), append(String),
4 public class StringBuffer_1
6 public static void main(String args
[])
8 StringBuffer sb
= new StringBuffer("45");
13 System
.out
.println (sb
);
17 String foo
= sb
.toString();
19 System
.out
.println (foo
);
21 System
.out
.println (foo
);
23 System
.out
.println (sb
);
24 sb
= new StringBuffer("1234");
25 System
.out
.println(sb
.reverse());
27 sb
= new StringBuffer("123456789");
29 System
.out
.println(sb
);
31 sb
.replace (2, 99, "foo");
32 System
.out
.println (sb
);
34 sb
= new StringBuffer("123456789");
35 sb
.replace (1, 1, "XX");
36 System
.out
.println (sb
);
38 sb
= new StringBuffer("123456789");
39 sb
.replace (0, 2, "XX");
40 System
.out
.println (sb
);
42 sb
= new StringBuffer("123456789");
43 sb
.replace (5, 9, "54321");
44 System
.out
.println (sb
);
46 sb
= new StringBuffer("123456789");
49 System
.out
.println (sb
);
56 catch (StringIndexOutOfBoundsException x
)
58 System
.out
.println (x
.getClass());
65 catch (StringIndexOutOfBoundsException x
)
67 System
.out
.println (x
.getClass());
74 catch (StringIndexOutOfBoundsException x
)
76 System
.out
.println (x
.getClass());
83 catch (StringIndexOutOfBoundsException x
)
85 System
.out
.println (x
.getClass());
92 catch (StringIndexOutOfBoundsException x
)
94 System
.out
.println (x
.getClass());
99 sb
.replace (-2, 2, "54321");
101 catch (StringIndexOutOfBoundsException x
)
103 System
.out
.println (x
.getClass());
108 sb
.replace (4, 2, "54321");
110 catch (StringIndexOutOfBoundsException x
)
112 System
.out
.println (x
.getClass());
117 sb
.replace (12, 18, "54321");
119 catch (StringIndexOutOfBoundsException x
)
121 System
.out
.println (x
.getClass());