File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change 4
4
import java .util .function .Consumer ;
5
5
import java .util .function .Predicate ;
6
6
7
- public class ArrayListCustom <T > implements Cloneable {
7
+ public class ArrayListCustom <T > implements Cloneable , Iterable < T > {
8
8
9
9
private final int DEFAULT_CAPACITY = 7 ;
10
10
private int size = 0 ;
@@ -114,7 +114,7 @@ public String toString() {
114
114
}
115
115
116
116
// forEach method takes Consumer<T>
117
- public void forEach (Consumer <T > o ) {
117
+ public void forEach (Consumer <? super T > o ) {
118
118
Objects .requireNonNull (o );
119
119
for (int i = 0 ; i < size ; i ++) {
120
120
o .accept ((T ) arr [i ]);
@@ -128,6 +128,11 @@ public ArrayListCustom<T> filter(Predicate<T> o) {
128
128
return newList ;
129
129
}
130
130
131
+ @ Override
132
+ public Iterator <T > iterator () {
133
+ return new ArrayListItr <>();
134
+ }
135
+
131
136
private class ArrayListItr <T > implements Iterator <T > {
132
137
int cursor = 0 ;
133
138
You can’t perform that action at this time.
0 commit comments