Read all elements in vector

We can read all elements in vector by following ways:

  • Read all elements in vector using iterator.
  • Read all elements in vector using Enumeration.

Read all elements in vector using iterator

package com.w3spoint;
 
import java.util.Iterator;
import java.util.Vector;
 
/**
 * Read all elements in vector using iterator
 * @author w3spoint
 */
public class ReadVectorElements {
  public static void main(String[] args) {
	Vector<String> vector = new Vector<String>();
        //Adding elements to the end
	vector.add("Jai");
	vector.add("Mahesh");
	vector.add("Hemant");
	vector.add("Vishal");
 
	Iterator<String> iterator = vector.iterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next());
        }
  }
}

Output

Jai
Mahesh
Hemant
Vishal

Read all elements in vector using Enumeration

package com.w3spoint;
 
import java.util.Enumeration;
import java.util.Vector;
 
/**
 * Read all elements in vector using Enumeration
 * @author w3spoint
 */
public class ReadVectorElements {
  public static void main(String[] args) {
	Vector<String> vector = new Vector<String>();
        //Adding elements to the end
	vector.add("Jai");
	vector.add("Mahesh");
	vector.add("Hemant");
	vector.add("Vishal");
 
	Enumeration<String> enumeration = vector.elements();
        while(enumeration.hasMoreElements()){
            System.out.println(enumeration.nextElement());
        }
  }
}

Output

Jai
Mahesh
Hemant
Vishal
Please follow and like us:
Content Protection by DMCA.com
togel situs toto situs togel situs toto situs toto agen togel situs togel situs togel togel situs togel resmi situs togel situs togel situs toto link togel togel online