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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -