How to read all elements in vector by using iterator?

Below example shows how to iterate through vector using iterator object. 

The steps are as follows:
1) Create a Vector
2) Add elements to it using add(Element E) method of Vector class
3) Obtain an iterator by invoking iterator() method of Vector.
4) Traverse the Vector using hasNext() and next() method of Iterator.

package pack2;

import java.util.Iterator;
import java.util.Vector;

public class VectorIteratorExample {

  public static void main(String[] args) {
    Vector<String> vct = new Vector<String>();
        //adding elements to the end
        vct.add("Slenium");
        vct.add("Java");
        vct.add("QTP");
        vct.add("SoapUI");
        Iterator<String> itr = vct.iterator();
        while(itr.hasNext()){
            System.out.println(itr.next());
        }

  }

}

Output:

Slenium
Java
QTP
SoapUI

The only business I know is learning new technology and spreading the knowledge. I believe sharing is learning. This is my prime reason to build this site.
I welcome and value your comments, suggestions and corrections.

310total visits,1visits today

The only business I know is learning new technology and spreading the knowledge. I believe sharing is learning. This is my prime reason to build this site. I welcome and value your comments, suggestions and corrections.