I have a List of String[6]s. I'm trying to build a List<List> that contains the unique String elements at each index.
For some reason, I frequently run into this problem, search to see if answers exist, experiment a lot, and end up building a working method that does not use stream, but takes up like 20 lines.
To clarify, with an example:
//Sample items: String[] items = "AD", "AR", "BC", "DA", "RA", "DD";
// String[] items2 = "AE", "AZ", "BU", "DI", "RE", "DP";
// String[] items3 = "AD", "AO", "BU", "DZ", "RW", "DP";
List<String[]> itemsList;
List<String>[] distinctItems;
If itemsList contains the sample Items, how can .stream() put them in distinctItems? distinctItems should look like:
//distinctItems[0].get(0) == "AD"
//distinctItems[0].get(1) == "AE"
//distinctItems[0].size() == 2 ; Has 2 unique elements in index 0
//distinctItems[1].get(0) == "AR"
//distinctItems[1].get(1) == "AZ"
//distinctItems[1].get(2) == "AO"
//distinctItems[1].size() == 3 ; Has 3 unique elements in index 1
I'm getting pretty good at .stream() but on certain compound data types (List of Array[]), I can't seem to find the right methods and solutions.
Any help greatly appreciated.
List<String[]>is basically a two-dimensional data structure. AList<List>[]is a three-dimensional data structure. I am not getting how you want to transform your source list. Besides that, where are your code attempts?