How to transform List to Map with Google collections?

前端 未结 5 740
名媛妹妹
名媛妹妹 2021-02-01 12:53

I have a list of strings and I have a function to generate a value for each key in the list.

I want to create a map using this function. Can I do this with Google collec

5条回答
  •  后悔当初
    2021-02-01 13:18

    Either I have misunderstood you or the other posters have. I understand that you want your list to be the map keys, while Maps.uniqueIndex() creates keys to map to your values (which is quite the opposite).

    Anyway, there is an open Guava issue that requests the exact functionality you are requesting, and I have also implemented such a solution for a previous question.

提交回复
热议问题