You are here:   HomeJava ProgrammingJava ArrayString matches() Methods in Java Examples
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("Ganga");
           vector.addElement("Orchids");
           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));
           vector.insertElementAt("Vanilla",2);
           vector.removeElementAt(0);
           n=vector.size();
           String arr[]=new String[n];
           vector.copyInto(arr);
                 for(i=0;i<=n-1;i++)
                     {
                       System.out.println(arr[i]);
                     }
     }  
}        

Vector elementAt() Java example





Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes 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.



What's New and Popular





Popular Article