-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStringBufferClass.java
More file actions
41 lines (35 loc) · 1.4 KB
/
StringBufferClass.java
File metadata and controls
41 lines (35 loc) · 1.4 KB
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
31
32
33
34
35
36
37
38
39
40
41
package strings;
public class StringBufferClass {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("hello String Buffer");
System.out.println(sb);
System.out.println(sb.hashCode() + " " + sb.capacity());
String st = new String("hello");
System.out.println(st);
sb.append(" welcome");
st.concat("welcome");
System.out.println(sb);
System.out.println(sb.hashCode() + " " + sb.capacity());
System.out.println(st);
StringBuffer sbe = new StringBuffer(25);
sbe.append("hello");
System.out.println(sbe + " " + sbe.length() + " " + sbe.capacity());
StringBuffer sbc = new StringBuffer();
System.out.println(sbc.capacity());
String stri = new String("world");
StringBuffer stbf = new StringBuffer(stri);
System.out.println(stbf);
stbf.insert(0, "hello ");
System.out.println(stbf);
System.out.println(stbf.reverse());
stbf.reverse(); // to reverse the reversed string again.
System.out.println(stbf.replace(0, 5, "hi!"));
StringBuffer stbfr = new StringBuffer(9);
System.out.println(stbfr.capacity());
stbfr.append("subhakanta");
System.out.println(stbfr);
System.out.println(stbfr.capacity());
stbfr.ensureCapacity(23);
System.out.println(stbfr.capacity());
}
}