Vector size() in Java

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

Syntax:

int java.util.Vector.size()

This method returns the number of components in this vector.

Parameters: NA

Returns: the number of components in this vector.

Exceptions: NA

Approach

Java

import java.util.Vector;

public class Vectorsize {
    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.size());
    }
}

Output:

4


No comments:

Post a Comment