如何收集双流列表
2022-09-02 20:13:33
我有以下代码:
Stream.of("1,2,3,4".split(",")).mapToDouble(Double::valueOf).collect(Collectors.toList());
我想回来。List<Double>
此代码不编译。
我看到错误:
Error:(57, 69) java: method collect in interface java.util.stream.DoubleStream cannot be applied to given types;
required: java.util.function.Supplier<R>,java.util.function.ObjDoubleConsumer<R>,java.util.function.BiConsumer<R,R>
found: java.util.stream.Collector<java.lang.Object,capture#1 of ?,java.util.List<java.lang.Object>>
reason: cannot infer type-variable(s) R
(actual and formal argument lists differ in length)
如何解决此问题?