java - Getting all objects with same key from a MultiValueMap -


i have multivaluemap<integer, path> trying [print purpose of question] out paths put in map using same key.

this current solution:

multivaluemap<integer, path> duplicates = duplicatefinder.getduplicates();  (map.entry<integer, object> entry: duplicates.entryset()) {   final integer key = entry.getkey();   final object obj = entry.getvalue();   (object o: (linkedlist)((arraylist)entry.getvalue()).get(0))     system.out.println(o);   system.out.println(); } 

i feel solution dangerous (casting , magic number 0) , avoid it. how can achieve desired result in more readable/safe manner?

the entry set seems declared unfortunate signature. iterate on keys instead, , call getcollection each:

for (integer key : duplicates.keyset()) {     collection<path> paths = duplicates.getcollection(key);     system.out.println("paths " + key);     (path path : paths) {         system.out.println("  " + path);     }     system.out.println(); } 

(note guava's multimap allow use duplicates.asmap().entryset() instead, , each entry have collection<v> value...)


Comments

Popular posts from this blog

python - Specify path of savefig with pylab or matplotlib -

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -