Java vector implementation.
Java vector implementation.
In this example, you will see the how to implements vector in java. The Vector is mutable class. The size of vector can be change depends on needs. There is a vector class constructor, that creates a empty object of vector class. And the add() method of vector class add elements in vector.
Code:
VectorExample.java
import java.util.Enumeration; import java.util.Vector; public class VectorExample { public static void main(String[] arr) { // creates a empty object of vector class Vector obVector=new Vector(); // Add elements in vector obVector.add(1); obVector.add(2); obVector.add(3); obVector.add(4); obVector.add(5); System.out.println("Elements in vactor class."); // creates a enumeration object of vector class. Enumeration obEnum=obVector.elements(); while (obEnum.hasMoreElements()) { System.out.print(obEnum.nextElement()+" "); } } }Output:
Elements in vactor class. 1 2 3 4 5 |
Download this code.
[ 0 ] Comments