|
|
|
|
12
|
//okay katrice, so public method is because this test does not create a instance of MapFunc
|
12
|
//okay katrice, so public method is because this test does not create a instance of MapFunc
|
13
|
//The <T, R> when its static you have to define the generic so you can pass it into a static
|
13
|
//The <T, R> when its static you have to define the generic so you can pass it into a static
|
14
|
//We are returning an Arraylist of the results and they take in an ArrayList of type T
|
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
|
}
|