Given: 2 Lists of String. Required: List<Pair<String, String>> countryStatus.
Following the answer from @geco17 with two for loops I am getting into OutOfMemoryError: Java Heap Space due to the amount of data.
Is there any other way to do so and avoid OutOfMemory Error?
Pairs two different list into a single map
for (String country : countrylist) {
for (String status : statusList) {
nodesCountryStatus.add(new Pair(country, status));
}
}
UPDATE: As a possible way to avoid this problem but to solve the task I had not straightforward I did the following - concatinating two lists by each element in sequence Zipping streams using JDK8 with lambda (java.util.stream.Streams.zip). I was to have the output in csv thus commas appropriate:
if (countries.size() == statuses.size()) { countryStatusAsExtracted = Streams.zip(countries.stream(), statuses.stream(), (a, b) -> (a + "," + b)) .collect(Collectors.toList());}