ensureCapacity(int): This method is available in java.util.Vector class of Java.
Syntax:
void java.util.Vector.ensureCapacity(int minCapacity)
This method takes one argument. This method increases the capacity of this vector, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument.
Parameters: One parameter is required for this method.
minCapacity: the desired minimum capacity.
Exceptions: NA
Approach
Java
import java.util.Vector;public class VectorensureCapacity {public static void main(String[] args) {Vector<String> vector = new Vector<>();vector.add("Hello");vector.add("Java");vector.add("C++");vector.add("Program");int minCapacity = 10;vector.ensureCapacity(minCapacity);System.out.println(vector);}}
Output:
[Hello, Java, C++, Program]
No comments:
Post a Comment