java - Convert Multiset to a Map -


Let me see a map & lt; String, integer & gt; (key, calculation) to be converted.

I can not find any utility function for this, is there anything less than the code below for this?

  Personal Static Maps & lt; String, integer & gt; MultisetToMap (last multiset & lt; string & gt; multiset) {Map & lt; String, integer & gt; Result = New Hashmap & lt; & Gt; (); (String element: multiset.elementSet ()) for {result.put (element, multiset.count (element)); } Return ImmutableMap.copyOf (results); } 

In fact, there is no hidden guava feature for it, Are doing the proper thing.

I did not find a feature request (open or otherwise) to fix this. But if we ever apply, then you may have another option.


Comments