Advertisement
Aldin-SXR

Iterator.class

Mar 5th, 2020
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.44 KB | None | 0 0
  1. /* Define the Iterator class, and hasNext() and next() methods */
  2. private class LinkedListIterator implements Iterator<Item> {        // 1
  3.     Node<Item> current = head;                                      // 2
  4.    
  5.     public boolean hasNext() {                                      // 3
  6.         return current != null;                                     // 3
  7.     }                                                               // 3
  8.        
  9.     public Item next() {                                            // 4
  10.         Item item = current.data;                                   // 4
  11.         current = current.next;                                     // 4
  12.         return item;                                                // 4
  13.     }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement