Java Vector trimToSize() MethodThe 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. SyntaxFollowing is the declaration of trimToSize() method: ParameterThis method does not accept any parameter. ReturnThe trimToSize() method does not return anything. It trims the capacity of the given vector with the current size. ExceptionsNA Compatibility VersionJava 1.2 and above Example 1Test it NowOutput: The elements of a vector are: Number = 1 Number = 2 Number = 3 Number = 4 Number = 5 Example 2Test it NowOutput: 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 |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India