Java Vector trimToSize() Method
The trimToSize() method of Java Vector class is used to trim the capacity of the vector to be the vector's current size. An application can use this operation to minimize the storage of a vector.
Following is the declaration of trimToSize() method:
This method does not accept any parameter.
The trimToSize() method does not return anything. It trims the capacity of the given vector with the current size.
Java 1.2 and above
Example 1Test it Now
The elements of a vector are: Number = 1 Number = 2 Number = 3 Number = 4 Number = 5
Example 2Test it Now
The initial size of the vector: 9 The elements of a vector are: White Green Black Pink Size of the vector after trimToSize(): 4