The
iterator() method of
Java AbstractCollection is used to return an iterator of the same elements as that of the Collection. The elements are returned in random order from what was present in the Collection.
Syntax:
Iterator iterate_value = AbstractCollection.iterator();
Parameters: The function does not take any parameter.
Return Value: The method iterates over the elements of the Collection and returns the values(iterators).
Below programs illustrate the use of AbstractCollection.iterator() method:
Program 1:
Output:
Collection: [4, Geeks, To, Welcome]
The iterator values are:
4
Geeks
To
Welcome
Program 2: