File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed
group08/769638826/src/main/java/com/coding/basic Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -76,13 +76,15 @@ public int size() {
76
76
}
77
77
78
78
public Iterator iterator () {
79
- return null ;
79
+ return new ListIterator () ;
80
80
}
81
81
82
82
private class ListIterator implements Iterator {
83
+ int cursor ;
84
+
83
85
@ Override
84
86
public boolean hasNext () {
85
- return size != 0 ;
87
+ return cursor != size ;
86
88
}
87
89
88
90
public void remove (){
@@ -91,12 +93,19 @@ public void remove(){
91
93
92
94
@ Override
93
95
public Object next () {
94
- if (!hasNext ()){
96
+ if (!hasNext ()) {
95
97
throw new NoSuchElementException ();
96
98
}
97
99
98
- //TODO
99
- return null ;
100
+ int i = cursor ;
101
+ if (i >= size )
102
+ throw new NoSuchElementException ();
103
+
104
+ Object [] elementData = ArrayList .this .elementData ;
105
+
106
+ cursor = i + 1 ;
107
+
108
+ return elementData [i ];
100
109
}
101
110
}
102
111
}
You can’t perform that action at this time.
0 commit comments