The example aims to iterate through the elements of Vector by ListIterator in Java.
Source Code
package com.beginner.examples;
import java.util.ListIterator;
import java.util.Vector;
public class IterateThroughVectorUsingListIterator {
public static void main(String[] args) {
//create Vector.
Vector vector = new Vector();
vector.add("A");
vector.add("B");
vector.add("C");
vector.add("D");
/*
* Get a ListIterator object for Vector using listIterator method.
*/
ListIterator listIterator = vector.listIterator();
System.out.println("Iterating through Vector elements :");
while(listIterator.hasNext()) {
System.out.println(listIterator.next());
}
}
}
Output:
Iterating through Vector elements :
A
B
C
D
References
Imported packages in Java documentation: