0
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?

2
  • new ArrayList<String>(); is a list of strings, not arrays. Voting to close as typo. Commented Mar 2, 2017 at 5:57
  • new ArrayList<String[]>(), or better yet new ArrayList<>() Commented Mar 2, 2017 at 5:58

1 Answer 1

1

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(","));
        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.