Vector trimToSize() method in Java with Example
The trimToSize() method of Vector in Java trims the capacity of an Vector instance to be the Vector’s current size. This method is used to trim an Vector instance to the number of elements it contains.
Parameter: It does not accepts any parameter.
Return Value: It does not returns any value. It trims the capacity of this Vector instance to the number of the element it contains. Below program illustrate the trimTosize() method:
Initial Vector is: [2, 4, 5, 6, 11] Initial size is: 5 Size after using trimToSize(): 5
Initial Vector is: [Geeks, 4, Geeks, Welcomes, You] Initial size is: 5 Size after using trimToSize(): 5
Time complexity: O(n). // n is the number of elements in the vector.
Auxiliary space: O(n).
My Personal Notes arrow_drop_up
Please Login to comment...