D
D
DarkByte20152017-06-02 19:24:43
Java
DarkByte2015, 2017-06-02 19:24:43

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

1 answer(s)
S
Sergey Gornostaev, 2017-06-02
@DarkByte2015

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 question

Ask a Question

731 491 924 answers to any question