Iterators in Java

  • Eclipse: Oxygen
  • Java: 1.8

The list of iterators in Java and iterators are shown here. The iterators are the same as for the foreach loop and do not have any additional features compared to the foreach loop. The list iterators have some interesting features like the previous one and more, which will be seen later.

In the following, Iterator is used for iterating in the list. hasNext() method of iterator check for next element in the collection and next() method returns the current element.

Output

Element: India

Element: USA

Element: Poland

Element: Egypt

Element: Thailand

Element: Russia

Contributed by: Poonam Tomar


Full stack Java Developer

   Buy me a coffee!

 

PayTM QR (INDIA)

Download file

Leave a Reply

avatar
  Subscribe  
Notify of
Close Menu