public
synchronized ListIterator<E> listIterator()
Returns
a list iterator over the elements in this list.
import java.util.*; class VectorListIterator{ public static void main(String args[]){ Vector<Integer> myVector; ListIterator<Integer> myIter; myVector = new Vector<> (); /*Add Elements to myVector*/ myVector.add(10); myVector.add(11); myVector.add(12); myVector.add(13); myVector.add(14); myIter = myVector.listIterator(); System.out.println("Elements in Forward order"); while(myIter.hasNext()){ System.out.print(myIter.next() +" "); } System.out.println("\nElements in Reverse order"); while(myIter.hasPrevious()){ System.out.print(myIter.previous() +" "); } } }
Output
Elements in Forward order 10 11 12 13 14 Elements in Reverse order 14 13 12 11 10
No comments:
Post a Comment