有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (2) 个答案

  1. # 1 楼答案

    您可以从entrySet获取流,并使用flatMapvalues生成另一个流:

    map.entrySet()
                .stream()
                .map(Map.Entry::getValue)
                .map(Map::entrySet)
                .flatMap(Set::stream)
                .map(Map.Entry::getValue)
                .flatMap(Set::stream)
                .collect(Collectors.toList());
    
  2. # 2 楼答案

    要将Map<String,Map<Long,CustomObject>>转换为List<CustomObject>,您可以这样做:

    Map<String,Map<Long,CustomObject>> input = ...
    List<CustomObject> output = new ArrayList<>();
    input.forEach((key, value) -> output.addAll(value.values()));