Vector class trimToSize() method example
Trims the capacity of this vector to be the vector's current size.
Vector class trimToSize() method example. This example shows you how to use trimToSize() method.This method Trims the capacity of this vector to be the vector's current size.
Here is the code:-
/*
* @Program that Trims the capacity of this vector to be the vector's current size.
* TrimToSize.java
* Author:-RoseIndia Team
* Date:-26-May-2008
*/
import java.util.*;
public class TrimToSize {
public static void main(String[] args) {
//Creating Vector with capacity 50
Vector v = new Vector(50);
//Adding elements in the vector
v.add("G");
v.add("I");
v.add("R");
v.add("I");
v.add("S");
v.add("H");
System.out.print("Capacity of the vector is: " + v.capacity());
//Trims the capacity of this vector to be the vector's current size.
System.out.println();
v.trimToSize();
System.out.print("Capacity of the vector after trimming is: " + v.capacity());
}
} |
Output of the program:-
Capacity of the vector is: 50
Capacity of the vector after trimming is: 6 |
|