Reputation: 99
String s[] = {"a,b,c", "d,e,f"};
I'd like to split each string up into arrays of subitems. So that I end up with something like this is pseudocode: [['a', 'b', 'c'], ['d', 'e', 'f']]
String arr[] = {"a,b,c", "d,e,f"};
List<String[]> groups = new ArrayList<String>();
for(String s : arr) {
groups.add(s.split(","));
}
Was hoping the above would do the trick, but I think I am misunderstanding my List declaration?
Upvotes: 0
Views: 91
Reputation: 374
Yes there is a small typo in you code. Use the below code.
String arr[] = {"a,b,c", "d,e,f"};
List<String[]> groups = new ArrayList<String[]>();
for(String s : arr) {
groups.add(s.split(","));
}
Upvotes: 1