dictionary - Java 8 list to map with stream -


i have list<item> collection. need convert map<integer, item> key of map must index of item in collection. can not figure out how streams. like:

items.stream().collect(collectors.tomap(...)); 

any help?

as question identified possible duplicate need add concrete problem - how position of item in list , put key value

you can create stream of indices using intstream , convert them map :

map<integer,item> map =      intstream.range(0,items.size())              .boxed()              .collect(collectors.tomap (i -> i, -> items.get(i))); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -