浏览代码

done pt 7, onto pt 8

Katrice Williams-Dredden 6 年前
父节点
当前提交
8aedfcd1e9
共有 1 个文件被更改,包括 7 次插入1 次删除
  1. 7
    1
      src/main/java/MapFunc/MapFunc.java

+ 7
- 1
src/main/java/MapFunc/MapFunc.java 查看文件

@@ -12,7 +12,13 @@ public class MapFunc {
12 12
     //okay katrice, so public method is because this test does not create a instance of MapFunc
13 13
     //The <T, R> when its static you have to define the generic so you can pass it into a static
14 14
     //We are returning an Arraylist of the results and they take in an ArrayList of type T
15
-    public static <T,R> ArrayList<R> map(ArrayList<T>, Function<T,R>){
15
+    public static <T,R> ArrayList<R> map(ArrayList<T> lists, Function<T,R> function){
16
+        ArrayList<R> result = new ArrayList<>();
17
+        for(T item: lists){
18
+            R entry = function.apply(item);
19
+            result.add(entry);
16 20
 
21
+        }
22
+        return result;
17 23
     }
18 24
 }