by Dinesh Thakur Category: array

The elements() method of the Vector class is used to retrieve an enumeration of the elements that were added to the vector. A while loop is then used to cycle through and print the elements contained in the enumeration. The hasMoreElements() method is used to determine whether the enumeration contains more elements. If it does, the nextElement() method is used to retrieve the object for printing.

The removeElement() of the Vector class is used to remove the vector element The for loop indexes each element in the vector using the elementAt() method.

import java.util.Vector;

import java.util.Enumeration;
class elementAtJavaExample
     public static void main(String args[])
           Vector vector = new Vector(4);
           int n,i;
           vector.addElement("Blue Demon");
           vector.addElement("Doble Cola");
           vector.addElement("Duke's Mangola");
           System.out.println("Capacity of vector is :" + vector.capacity());
                 System.out.println("First element is :" + vector.firstElement());
           System.out.println("Last element is :" + vector.lastElement());
           System.out.println("Third element is :" + vector.elementAt(3));
           System.out.println("Orchids is at position: " + vector.indexOf("Orchids",0));
           String arr[]=new String[n];

Vector elementAt() Java example

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles