怎么把 Map<Long, List<Entity>> 用 Stream 打平成 Set<Long>?

现在我有一个数据结构Map>。其中 Entity 包含 一个 Long id 字段
不管key什么,我只想取出这个 map 的 id 字段,最终变成一个 id 集合 Set
大家有什么 stream 使用方法吗

flatMap
https://howtodoinjava.com/java8/stream-flatmap-example/

遍历map,用迭代器方式,然后可以对应取到value值,也就是你的List,然后在遍历list,在取值放进set中

Map<Long, List<Person>> map = new HashMap();
        map.values().stream().flatMap(list->list.stream())
                .map(entity->entity.getId()).collect(Collectors.toSet());