We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent de8a0dd commit 19a2abeCopy full SHA for 19a2abe
Medium/Peeking Iterator.java
@@ -4,20 +4,20 @@
4
class PeekingIterator implements Iterator<Integer> {
5
Integer nextElement;
6
Iterator<Integer> iterator;
7
- public PeekingIterator(Iterator<Integer> iterator) {
+ public PeekingIterator(Iterator<Integer> iterator) {
8
// initialize any member here.
9
this.iterator = iterator;
10
updateNext();
11
- }
+ }
12
13
private void updateNext() {
14
nextElement = iterator.hasNext() ? iterator.next() : null;
15
}
16
17
// Returns the next element in the iteration without advancing the iterator.
18
- public Integer peek() {
+ public Integer peek() {
19
return nextElement;
20
21
22
// hasNext() and next() should behave the same as in the Iterator interface.
23
// Override them if needed.
0 commit comments