0

I have a Map <String, Set<String>>. I am trying to convert it to a SetMultiMap<String, String>. Is that conversion possible since Guava doesn't seem to like converting a Map to a SetMultiMap?

Joe C
  • 15,324
  • 8
  • 38
  • 50
chrisrhyno2003
  • 3,906
  • 8
  • 53
  • 102
  • 2
    It's a simple enough using a loop or two. Are you asking if there's a shortcut? – shmosel Feb 13 '17 at 22:49
  • Yeah. I looked at a previous example. Multimaps.newMultimap(map, ArrayList::new). Seems like pretty straight forward. I was wondering since Set is an abstract, can we not do it the above way? – chrisrhyno2003 Feb 13 '17 at 22:50
  • You could use something like `Multimaps.newSetMultimap(new HashMap<>(), HashSet::new)`, but it won't help for your purpose, since the map must be empty. See [this discussion](http://stackoverflow.com/questions/3093863/how-to-create-a-multimapk-v-from-a-mapk-collectionv#comment3172265_3093893). – shmosel Feb 13 '17 at 22:54
  • 1
    You will have to explicitly loop through and copy. Guava does not provide any other way. – Louis Wasserman Feb 13 '17 at 23:05

0 Answers0