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

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 08-Feb-2018 09:00:00
Advertisements