将迭代器的迭代器转换为列表?

时间:2020-06-29 16:55:30

标签: java iterator java-stream

我正在尝试将JsonNodes列表转换为fieldNames列表。

这就是我拼凑的东西:

final ResponseBody<JsonNode> body = state.getResponse().getBody();
final List<JsonNode> actualEntryList = body.jsonPath().getList('path.to.something');

final List<String> actualKeyList = actualEntryList.stream()
    .flatMap(node ->                                   // flatmap needs to return a stream
        StreamSupport.stream(node.fieldNames(), false) // fieldNames return an iterator
    ).collect(Collectors.toList());

但是我收到错误Cannot infer type argument(s) for <R> flatMap(Function<? super T, ? extends Stream<? extends R>>),这让我觉得我做错了吗?

我应该如何进行转换?

0 个答案:

没有答案