Java Vector Iterator


 

Java Vector Iterator

In this segment of tutorial we will learn about the Vector class and its use with the Iterator interface.Then We will create an example to print the content of the a Vector.

In this segment of tutorial we will learn about the Vector class and its use with the Iterator interface.Then We will create an example to print the content of the a Vector.

  • Java Vector Iterator is a Collection class. It has similar functionality as of the Array.
  • Its size is variable
  • It has growable array. Its size may increase or decrease.
  • It has iterator() method. So Iterator interface can traverse all its elements.


Java Vector Iterator Example
import java.util.Iterator;
import java.util.Vector;

public class vector1 {

	public static void main(String[] args) {
		Vector v = new Vector();
		String tree[] = { "olive", "oak", "grass", "mango" };
		for (String s : tree) {
			v.add(s);
		}
		Iterator it = v.iterator();
		for (; it.hasNext();)
			System.out.println(it.next());
	}
}

Output

olive oak grass mango

Ads