Vector Iterator Java Example


 

Vector Iterator Java Example

This segment of tutorial illustrates about the Vector class and its use with the Iterator interface.We will create an example to print the content of the a Vector.

This segment of tutorial illustrates about the Vector class and its use with the Iterator interface.We will create an example to print the content of the a Vector.

  • Vector is a collection class.It works similar to the Array.
  • 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 with Example
import java.util.Iterator;
import java.util.Vector;

public class vector {

	public static void main(String[] args) {
		Vector v = new Vector();
		String city[] = { "delhi", "hongkong", "dubai", "sanghai" };
		for (String s : city) {
			v.add(s);
		}
		Iterator it = v.iterator();
		for (; it.hasNext();)
		System.out.println(it.next());
	}
}

Output

delhi hongkong dubai sanghai

Ads