I ran into a requirement to store multiple values for a single key so I came to learn about Multimap of Guava.
Now in my code there is requirement to retrieve Key: Value K: V[] where in this case the value will be an array as I am storing multiple values for same key, into a list as:
List<Map.Entry<String, String>
Below is how I tried to get it done:
List<Map.Entry<String, String>> mapCall = (List<Map.Entry<String, String>>) multimap.entries();
Above code is supposed to return a Collection, here a List, of each Entry<String, String>.
And below is how it has failed: Error:
java.lang.ClassCastException: com.google.common.collect.AbstractMultimap$4 cannot be cast to java.util.List
I think the Collection returned here by calling entries() method on Multimap is not of the Java Collections type. Unable to find an exact way to get it done.
What should be the proper way to achieve this??
Aucun commentaire:
Enregistrer un commentaire