Vector class size() method example
Returns the number of components in this vector.
Vector class size() method example. This example shows you how to use size() method.This method Returns the number of components in this vector.
Here is the code:-
/*
* @Program that Returns the number of components in this vector.
* Size.java
* Author:-RoseIndia Team
* Date:-26-May-2008
*/
import java.util.*;
public class Size {
public static void main(String[] args) {
Vector v = new Vector();
v.add("Rose");
v.add("India");
v.add("Rohini");
Enumeration e = v.elements();
System.out.print("Elements of the vector is : ");
while (e.hasMoreElements()) {
System.out.print(e.nextElement() + "\t");
}
System.out.println();
// Returns the number of components in this vector.
int i = v.size();
System.out.println("Size of vector is: " + i);
}
} |
Output of the program:-
Elements of the vector is : Rose India Rohini
Size of vector is: 3 |
|