I have the below code and would like to use java 8 to convert a list of Long
to a Map<Long,Long>
.
Long globalVal= 10;
List<Long> queryLongs = Arrays.asList(600L,700L,800L);
Map<Long, Long> map = queryLongs.stream().collect(Collectors.toMap(i->i, globalVal)));
I get an error when I try to map the individual value in the list as the key of the map.
The second argument of toMap
is also a Function
, so you can't just pass globalVal
.
Map<Long, Long> map = queryLongs.stream()
.collect(Collectors.toMap(Function.identity(),
i->globalVal));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With