Java Reference
In-Depth Information
85
Moves the iterator past the next
element.
86 @return
the traversed element
87 */
88
public
E next()
89 {
90
if
(!hasNext())
91
throw new
NoSuchElementException();
92 previous = position; //
Remember
for remove
93
94
if
(position ==
null
)
95 position = first;
96
else
97 position = position.next;
98
99
return
position.data;
100 }
101
102 /**
103
Tests if there is an element after
the iterator
104
position.
105 @return
true if there is an
element after the iterator
106
position
107 */
108
public boolean
hasNext()
109 {
110
if
(position ==
null
)
111
return
first ! =
null
;
112
else
113
return
position.next !=
null
;
114 }
115
116 /**
117
Adds an element before the
iterator position
118
and moves the iterator past the
inserted element.
119 @param element
the element to add
120 */