public
Vector()
Constructs
an empty vector with default capacity 10.capacity increment is zero
by default.
import java.util.*; class VectorConstructor{ public static void main(String args[]){ Vector<Integer> myVector = new Vector<> (); System.out.print("Size of myVector is "); System.out.println(myVector.size()); System.out.print("Capacity of myVector is "); System.out.println(myVector.capacity()); /*Adding Elements to Vector */ System.out.println("\nAdd 5 Elements to myVector"); myVector.add(10); myVector.add(20); myVector.add(30); myVector.add(40); myVector.add(50); System.out.print("\nSize of myVector is "); System.out.println(myVector.size()); System.out.print("Capacity of myVector is "); System.out.println(myVector.capacity()); } }
Output
Size of myVector is 0 Capacity of myVector is 10 Add 5 Elements to myVector Size of myVector is 5 Capacity of myVector is 10
No comments:
Post a Comment