Javatpoint Logo
Javatpoint Logo

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.

Syntax

Following is the declaration of trimToSize() method:

Parameter

This method does not accept any parameter.

Return

The trimToSize() method does not return anything. It trims the capacity of the given vector with the current size.

Exceptions

NA

Compatibility Version

Java 1.2 and above

Example 1

Test it Now

Output:

The elements of a vector are:
Number = 1
Number = 2
Number = 3
Number = 4
Number = 5

Example 2

Test it Now

Output:

The initial size of the vector: 9
The elements of a vector are:
 White
 Green
 Black
 Pink
Size of the vector after trimToSize(): 4

Next TopicJava Vector





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA