Share on Google+Share on Google+

Vector Iterator Java Example

Advertisement
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

Advertisements

Posted on: November 3, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.