Guava : LinkedHashMultimap values as list and not String -
i reading guava's linkedhashmultimap
, thought might useful me.
i have requirement such have map follows:
key:value b c d p q p r
if above input in map, want use linkedhashmultimap
create map like:
key : value list<b,c,d> p list<q,r>
tried using linkedhashmultimap
has following issue:
maplen.entries().stream().foreach(entry -> { system.out.println("maptemp2 key + " + entry.getkey()); system.out.println("maptemp2 value + " + entry.getvalue()); });
above prints string
values in map , not list<string>
.
can pointout how can done.
(kindly note: aware of normal core java solution of iterating, checking , creating list , inserting map.)
as can see in javadoc, multimap#entries()
returns collection<map.entry<k,v>>
- basically, iterate on each key/value pair, instead of key/(value set). so, try turning multimap<k, v>
standard map<k, list<v>>
. can multimap#asmap()
, code like:
maplen.asmap().entryset().stream().foreach(entry -> { system.out.println("maptemp2 key + " + entry.getkey()); system.out.println("maptemp2 value + " + entry.getvalue()); });
ps. guess missed parenthesis after ...entries
- it's method, not property, should have used:
// vv down here maplen.entries().stream().foreach(entry -> { system.out.println("maptemp2 key + " + entry.getkey()); system.out.println("maptemp2 value + " + entry.getvalue()); });
Comments
Post a Comment