我正在尝试创建一个HashSet< Byte>使用
Java 8 Streams API的字节1,2,3,… 9.我想使用IntStream,然后将值降级为byte就可以了.
我正在尝试变种
的HashSet nums = IntStream.range(1,10).collect(Collectors.toSet());
的HashSet nums = IntStream.range(1,10).map(e – >((byte)e)).collect(Collectors.toSet());
但这些都不起作用.
Error:(34,73) java: method collect in interface java.util.stream.IntStream cannot be applied to given types;
required: java.util.function.Supplier,java.util.function.ObjIntConsumer,java.util.function.BiConsumer
found: java.util.stream.Collector>
reason: cannot infer type-variable(s) R
(actual and formal argument lists differ in length)
我需要做flatMap或mapToObject吗?