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 4ad71a0 commit 247719dCopy full SHA for 247719d
src/Lists/ArrayListCustom.java
@@ -2,6 +2,8 @@
2
3
import java.util.*;
4
import java.util.function.Consumer;
5
+import java.util.function.Function;
6
+import java.util.function.Predicate;
7
8
public class ArrayListCustom<T> implements Cloneable {
9
@@ -120,6 +122,16 @@ public void forEach(Consumer<T> o) {
120
122
}
121
123
124
125
+ public ArrayListCustom<T> filter(Predicate<T> o) {
126
+ ArrayListCustom<T> newList = new ArrayListCustom<>();
127
+ this.forEach((item) -> {
128
+ if (o.test(item)) {
129
+ newList.add(item);
130
+ }
131
+ });
132
+ return newList;
133
134
+
135
public Object[] toArray() {
136
Object[] ret = new Object[size];
137
for (int i = 0; i < size; i++) {
0 commit comments