Why is my collect Collectors.toList()
showing this error:
Expected 3 argument but found 1
package com.knoldus;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
interface Cityeration<T> {
public abstract List<T> Cityeration(List<T> first, List<T> Second);
}
public class ListMultiplication {
public static void main(String s[]) {
List firstList = Arrays.asList(1, 2, 3, 4, 5);
List secondList = Arrays.asList(1, 2, 3, 4, 5);
Cityeration c = (first, second) -> IntStream.range(0, first.size())
.map(i -> first.get(i) * second.get(i))
.collect(Collectors.toList());
}
}
IntStream
. It doesn't have a.collect(Collector<...>)
method, does it? Seems you're expecting to use the collectors available forStream<T>
– ernest_k Feb 27 '20 at 16:53.boxed()
before the collect. – Andy Turner Feb 27 '20 at 16:59mapToObj
instead ofmap
) – Andy Turner Feb 27 '20 at 17:05