public
synchronized void trimToSize()
Trims the
capacity of this vector to be the vector's current size.
import java.util.*; class VectorTrimSize{ public static void main(String args[]){ Vector<Integer> myVector; myVector = new Vector<> (15, 5); myVector.add(10); System.out.print("Capacity of myVector is "); System.out.println(myVector.capacity()); System.out.print("size of myVector is "); System.out.println(myVector.size()); myVector.trimToSize(); System.out.println("\nTrimming to Size"); System.out.print("\nCapacity of myVector is "); System.out.println(myVector.capacity()); } }
Output
Capacity of myVector is 15 size of myVector is 1 Trimming to Size Capacity of myVector is 1
No comments:
Post a Comment