Java 8 convert List to Lookup Map

前端 未结 9 2060
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-12 03:29

I have a list of Station, in each Station there is a list of radios. I need to create a lookup Map of radio to Station. I know how to use Java 8 stream forEach to do it:

9条回答
  •  不知归路
    2021-01-12 04:21

    How about:

    radioToStationMap = StreamEx.of(stationList)
            .flatMapToEntry(s -> StreamEx.of(s.getRadioList()).mapToEntry(r -> s).toMap())
            .toMap();
    

    By StreamEx

提交回复
热议问题