Vector class setSize(int newSize) method example
Sets the size of this vector.
Vector class setSize(int newSize) method example. This example shows you how to use setSize(int newSize) method.This method Sets the size of this vector.
Here is the code:-
/*
* @Program that Sets the size of this vector.
* SetSize.java
* Author:-RoseIndia Team
* Date:-26-May-2008
*/
import java.util.*;
public class SetSize {
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.
System.out.println("Size of vector is: " + v.size());
//Sets the size of this vector.
v.setSize(5);
System.out.println("Size of vector after setting is: " + v.size());
}
}
|
Output of the program:-
Elements of the vector is : Rose India Rohini
Size of vector is: 3
Size of vector after setting is: 5 |
|