-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrBuffer.java
More file actions
26 lines (22 loc) · 918 Bytes
/
Copy pathstrBuffer.java
File metadata and controls
26 lines (22 loc) · 918 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
//package JavaString;
public class strBuffer {
public static void main(String[] args) {
// StringBuffer is mutable
// StringBuffer s = new StringBuffer();
StringBuffer s = new StringBuffer("SECE: ");
System.out.println(s.capacity()); // Capacity is 16 by default
// Error: Can't convert StringBuffer to String
// s = s + "Hello";
System.out.println(s.length());
// Append some content to StringBuffer
System.out.println(s.append("Hello, II CSE C!"));
System.out.println(s.capacity());
System.out.println(s.length());
// If the capacity of StringBuffer gets full after adding
// an extra String, the new capacity of StringBuffer will be
// (previousCapacity + 1) * 2
System.out.println(s.append("!"));
System.out.println(s.length());
System.out.println(s.capacity());
}
}