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
Post a Comment