Answer the question
In order to leave comments, you need to log in
How to get a dictionary from arrays of keys and values?
There is an array of keys and an array of values (string). It is necessary to receive the dictionary (Map) from them. Please tell me how to do this in a modern style? StreamAPI and all that... Is there any analogue of the zip function (there are many places, even in python, even in php, even in c#)? Googled another way through collect(Collectors.toMap()), but could not figure out how to apply it for my purpose.
Answer the question
In order to leave comments, you need to log in
Map<String, String> map = IntStream.range(0, Math.min(keysList.size(), valuesList.size()))
.boxed()
.collect(Collectors.toMap(keysList::get, valuesList::get));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question