Syntax error What does the method int capacity() do in java?

What does the method int capacity() do in java?



The capacity() method is used to return the current capacity of a vector. Capacity is the length of the array kept in the vector.

Example

import java.util.Vector;
public class VectorDemo {
   public static void main(String[] args) {

      Vector<Integer> vec = new Vector<Integer>();
      vec.add(14);
      vec.add(13);
      vec.add(12);
      vec.add(11);
      vec.add(4);
      vec.add(3);
      vec.add(2);
      vec.add(1);
      System.out.println("Capacity of the vector is :"+vec.capacity());
   }
}

Output

Capacity of the vector is :10
Updated on: 2020-02-25T10:06:15+05:30

343 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements