-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvector1.java
31 lines (31 loc) · 1.53 KB
/
vector1.java
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
import java.util.*;
class Vector1
{
public static void main(String args[])
{
Vector<String> vec = new Vector<String>(4);
vec.add(" Tiger");
vec.add(" Lion");
vec.add(" Dog");
vec.add(" Elephant");
System.out.println("\n Size is: "+vec.size());
System.out.println("\n Default capacity is: "+vec.capacity());
System.out.println("\n Vector element is: "+vec);
vec.addElement(" Rat");
vec.addElement(" Cat");
vec.addElement(" Deer");
System.out.println("\n Size after addition: "+vec.size());
System.out.println("\n Capacity after addition is: "+vec.capacity());
System.out.println("\n Elements are: "+vec);
if(vec.contains(" Tiger"))
{
System.out.println("\n Tiger is present at the index " +vec.indexOf("Tiger"));
}
else
{
System.out.println("\n Tiger is not present in the list.");
}
System.out.println("\n The first animal of the vector is = "+vec.firstElement());
System.out.println("\n The last animal of the vector is = "+vec.lastElement());
}
}