-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVectorDemo.java
More file actions
25 lines (25 loc) · 815 Bytes
/
VectorDemo.java
File metadata and controls
25 lines (25 loc) · 815 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
import java.util.*;
class VectorDemo{
public static void main(String args[]){
Vector<Integer> v = new Vector<Integer>(3,1);
System.out.println("Initial size: " + v.size());
System.out.println("1) Initial capacity: " + v.capacity());
v.addElement(3);
v.addElement(1);
v.addElement(4);
v.addElement(5);
System.out.println("2) Capacity after additions: " + v.capacity());
v.addElement(9);
System.out.println("3) current capacity: " + v.capacity());
System.out.println("First Element: " + v.firstElement());
System.out.println("Last Element: " + v.lastElement());
if(v.contains(3)){
System.out.println("Vector contains 3");
}
Iterator<Integer> vItr = v.iterator();
System.out.println("Elements in vector: ");
while(vItr.hasNext()){
System.out.print(vItr.next() + " ");
}
}
}