-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringBufferDemo.java
More file actions
30 lines (24 loc) · 772 Bytes
/
StringBufferDemo.java
File metadata and controls
30 lines (24 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package ch18.stringprocessing;
import java.util.*;
public class StringBufferDemo {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("Hello this is me");
System.out.println("buffer before = " + sb);
System.out.println("chatAt(1) before = " + sb.charAt(1));
sb.setCharAt(1, 'i');
// sb.setLength(2);
System.out.println("buffer after = " + sb);
System.out.println("charAt(1) after = " + sb.charAt(1));
char[] c = new char[4];
sb.getChars(1, 5, c, 0);
System.out.println(c);
StringBuffer sb2 = new StringBuffer("Hello Mom!");
sb2.setCharAt(1, 'i');
System.out.println(sb2);
sb2.append(" I am here");
System.out.println(sb2);
char ca[] = new char[5];
sb2.getChars(0, 5, ca, 0);
System.out.println(ca);
}
}