-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex03_Vector.java
More file actions
38 lines (30 loc) · 856 Bytes
/
ex03_Vector.java
File metadata and controls
38 lines (30 loc) · 856 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
31
32
33
34
35
36
37
38
package cse3040_16;
import java.util.Vector;
public class ex03_Vector {
public static void main(String[] args) {
Vector<String> v = new Vector<>(5);
v.add("1");
v.add("2");
v.add("3");
print(v);
v.trimToSize();
System.out.println("=== After trimToSize() ===");
print(v);
v.ensureCapacity(6);
System.out.println("=== After ensureCapacity() ===");
print(v);
v.setSize(7);
System.out.println("=== After setSize(7) ===");
print(v);
// setSize가 두배 이상으로 설정한 경우에는 capacity도 그 숫자로 맞춰준다.
// setSize가 두배가 안되면 그 숫자의 두배까지 capacity로 맞춰준다
v.clear();
System.out.println("=== After clear() ===");
print(v);
}
public static void print(Vector<?> v) {
System.out.println(v);
System.out.println("size: "+v.size());
System.out.println("capacity: " + v.capacity());
}
}