Retrieve the dynamic capacity of a list

In this section you will learn to get the capacity of a list i.e. retrieving the number of objects contained in it. Here is an example that provides the usage of the size() method in more detail.

Retrieve the dynamic capacity of a list 

     

In this section you will learn to get the capacity of a list i.e. retrieving the number of objects contained in it. Here is an example that provides the usage of the size() method in more detail. 

Create a class "VecSize" with a Vector. Populate it with the integer objects using add(object) method. Now retrieve the total number of objects contained in it using the size() method.

Here is the Code of the Example :

VecSize.java:

import java.util.*;
public class VecSize{
  public static void main(String argv[]){
  Vector v = new Vector();
  v.add(new Integer(1));
  v.add(new Integer(2));
  v.add(new Integer(3));
  v.add(new Integer(4));
  System.out.println("Vector Size: " v.Size());
  }
}

Here is the Output of the Example :

C:\roseindia>javac VecSize.java

C:\roseindia>java VecSize
Vector Size: 4

Advertisements

Share on Google+Share on Google+

Retrieve the dynamic capacity of a list

Posted on: February 28, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Retrieve the dynamic capacity of a list  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
Nikita shah
August 15, 2011
Retrieve the dynamic capacity of a list

Here in the given prog plz do method name size insted of Size() it will not give u error.

Ads

 

Ads