如何将 Collectors.toList() 转换为 Stream?

问题描述 投票:0回答:0

我有这样的方法

public Map<String, Stream<String>> phoneNumbers(List<Stream<String>> numsList) {
        return numsList.stream()
                .flatMap(Function.identity())
                .map(l -> l.replaceAll("[^0-9]", ""))
                .collect(Collectors.groupingBy(
                    n -> n.length() == 10 ? n.substring(0, 3)
                        : (n.length() == 7 ? "loc" : "err"),
                    Collectors.mapping(
                        n -> n.length() == 10 ? n.substring(3) : n,
                        Collectors.toList())));

但我需要将 Streams 作为 Map 值返回。

我试图将最后一行更改为

  Collectors.toList().stream())));

但是得到编译错误:

'The method stream() is undefined for the type Collector<Object,capture#1-of ?,List<Object>>'

我应该在这里做什么?将感谢任何建议!

java stream java-stream collectors
© www.soinside.com 2019 - 2024. All rights reserved.