I have two arrays of Strings. How can I loop through both arrays at once to create a HashMap<String, String> where the key is coming from first array and the value is coming from the second array?
eg.
Array1 = {"A", "B", "C", "D"}
Array2 = {"apple", "boy", "cat", "dog"}
Resulting HashMap:
[{A:apple}, {B:boy}, {C:cat}, {D:dog}]
Here is my code, but it's not working.
AtomicInteger index = new AtomicInteger();
Stream<String> stream = Stream.of(array2);
stream.forEach(x -> mappedData.put(array1[index.getAndIncrement()],x));