zipprrr
zipprrr

Reputation: 99

An ArrayList of Arrays of Strings

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

Answers (1)

Sunil
Sunil

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

Related Questions