如何将Collection<Integer>转换为Spliterator.OfInt?我试过很多方法,但都没成功。我可以这样做:
Collection<Integer> coll = new ArrayList<>();
Spliterator<Integer> ints = coll.spliterator();但是我想要一个Spliterator.OfInt而不是Spliterator<Integer>。如何才能做到这一点?
发布于 2020-05-23 17:00:46
您可以从.stream()获取Stream<Integer>,然后从mapToInt获取IntStream,最后调用spliterator获取Spliterator.OfInt
Spliterator.OfInt ofInt = coll.stream().mapToInt(i -> i).spliterator();发布于 2020-05-23 17:12:45
您需要提供拆箱操作,所以类似这样的操作将会起作用:
Collection<Integer> coll = ...
Spliterator.OfInt spliterator = coll.stream().mapToInt(Integer::intValue).spliterator();https://stackoverflow.com/questions/61969646
复制相似问题