Implementing Iterator pattern of a single Linked List |  ; creating a list ; elements to be added at the end . in the above created list . ; elements of list are retrieved through iterator .
import java . util . * ; class GFG { public static void main ( String [ ] args ) { ArrayList < Integer > list = new ArrayList < > ( ) ; list . add ( 1 ) ; list . add ( 2 ) ; list . add ( 3 ) ; Iterator < Integer > it = list . iterator ( ) ; while ( it . hasNext ( ) ) { System . out . print ( it . next ( ) + " ▁ " ) ; } } }