Vector capacity() in Java

capacity(): This method is available in java.util.Vector class of Java.

Syntax:

int java.util.Vector.capacity()

This method returns the current capacity of this vector.

Parameters: NA

Returns: the current capacity.

Exceptions: NA

Approach

Java

import java.util.Vector;

public class Vectorcapacity {
    public static void main(String[] args) {

        Vector<String> vector = new Vector<>();

        vector.add("Hello");
        vector.add("Java");
        vector.add("C++");
        vector.add("Program");

        System.out.println(vector.capacity());
    }
}

Output:

10


No comments:

Post a Comment