-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDemo3.java
More file actions
22 lines (18 loc) · 729 Bytes
/
Copy pathDemo3.java
File metadata and controls
22 lines (18 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class Demo3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String a = new String("hello"); // Immutable + String Pool
StringBuilder sb = new StringBuilder();
//StringBuffer sb = new StringBuffer(100);
//StringBuffer sb = new StringBuffer("hello"); // Mutable + No Pool
// hello + 16 = 5 + 16 = 21
System.out.println(sb.length());
System.out.println(sb.capacity());
sb.ensureCapacity(2000);
sb.append("How are you i am fine thank u jhjhgjghjhgjhjhjhjhgjghjhgjhgjhgjghjghjhgjhgjhgjghjghjghjghjghjghjghjgj");
System.out.println("Length "+sb.length());
System.out.println("Capcity "+sb.capacity());
// NewCapacity = OldCapacity * 2 + 2
// 44 = 21 * 2 + 2
}
}