I am trying to intersect each element in a list containing String []
with one another. Each element (String[]
) in the input list will be of length 3 or 4
Input: [{'J', 'K', 'L'}, {'G', 'H', 'I'}]
Output: ["JG", "JH", "JI",
"KG", "KH", "KI",
"LG", "LH", "LI"]
Input: [{'J', 'K', 'L'}, {'G', 'H', 'I'}, {'A', 'B', 'C'}]
Output: ["JGA", "JGB", "JGC",
"KGA", "KGB", "KGC",
"LGA", "LGB", "LGC",
"JHA", "JHB", "JHC",
"KHA", "KHB", "KHC",
"LHA", "LHB", "LHC",
"JIA", "JIB", "JIC",
"KIA", "KIB", "KIC",
"LIA", "LIB", "LIC"]
The size of each element in the output is equal to the total elements in the input list.
I've done the following but am not getting the correct results.
ArrayList<String> output = new ArrayList();
for (String [] s : InputList)
for (int i = 0; i < s.length; i++) {
if (output.size < 3)
output.add(s[i])
else {
output.add(output.get(i)+s[i]);
}
}
}