I am working in a project where I have two lists and need to map every single data on one list with the other list. Kind of a m * n mapping. How can we implement this code efficiently?
arr1[] = {"CAR", "TRUCK", "BUS"};
arr1[] = {"COLOR", "ENGINE"};
resulting array = {"CAR_COLOR", "CAR_ENGINE", "TRUCK_COLOR", "TRUCK_ENGINE", "BUS_COLOR", "BUS_ENGINE"}
n
and one of sizem
) will always containn*m
elements. This is the best you can do, because each element has to be generated. Are you asking about methods to not need to hold all of the lists in memory? No solution is going to be faster thanO(n*m)
. – WelbogArrays.stream(arr1).flatMap(a -> Arrays.stream(arr2).map(b -> a + "_" + b)).toArray(String[]::new)
– shmosel