Home Tutorial Java Iterator Vector Iterator Java Example

 
 

Vector Iterator Java Example
Posted on: November 3, 2009 at 12:00 AM
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

Related Tags for Vector Iterator Java Example:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.