public
Iterator<E> iterator()
Returns
an iterator over the elements in this list. This implementation
returns a list iterator over the list.
import java.util.*; class ArrayListIterator1{ public static void main(String args[]){ ArrayList<Integer> myList; Iterator<Integer> myIter; myList = new ArrayList<> (); /* Add Elements to myList */ myList.add(10); myList.add(123); myList.add(321); myList.add(456); myIter = myList.iterator(); System.out.println("Elements in myList are"); while(myIter.hasNext()){ System.out.println(myIter.next()); } } }
Output
Elements in myList are 10 123 321 456
No comments:
Post a Comment