Java Vector ensureCapacity() MethodThe ensureCapacity() method of Java Vector class is used to increase the capacity of the vector which is in use, if necessary. It ensures that the vector can hold at least the number of components specified by the minimum capacity argument. Syntax:Following is the declaration of ensureCapacity() method: Parameter:
Returns:The ensureCapacity() method has return type void so, it does not return anything. Exceptions:NA Compatibility Version:Java 1.2 and above Example 1:Test it NowOutput: Minimum capacity of this vector: 25 Example 2:Test it NowOutput: Element: [50, green, red] Capacity of the vector is: 10 New Capacity of the vector is:20 Example 3:Test it NowOutput: Element of the vector: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] Vector size: 10 Vector element after ensuring capacity: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] New vector size: 20 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