3:33 am - Friday May 26, 2017

Remove Capacity of a vector void trimToSize()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

                         The trimToSize() method is used to trim the capacity of this vector to be the vector’s current size. If the capacity of this vector is larger than its current size,  then the capacity is changed to current size.

Example Program

import java.util.Vector;

public class VectorTrimToSize

 {

	public static void main(String[] args)

	{

		Vector<Integer> h = new Vector<Integer>(7);

		h.add(0);

		h.add(1);

		h.add(2);

		System.out.println("Size of the vector: " + h.capacity());

		System.out.println("Trimming value");

		h.trimToSize();

		System.out.println("Now the Size : " + h.capacity());

	}
}

Output

   Size of the vector: 7

   Trimming value

   Now the Size : 3

BACK

Filed in: Java Examples

Comments are closed.