0

Ok, look. I have ArrayList<ArrayList<String>> which contains 3 different ArrayList<String> items. I'm passing this ArrayList<ArrayList<String>> to client.

I'm stuck at "extracting" items from this ArrayList<ArrayList<String>>. How can I "extract" items from ArrayList<ArrayList<String>> to 3 different ArrayList<String>??? In one turn(optionally); Thanks in advance!

1 Answer 1

1

If you know there are three, and your ArrayList<ArrayList<String>> is called bigList, it's as simple as

ArrayList<String> first = bigList.get(0);
ArrayList<String> second = bigList.get(1);
ArrayList<String> third = bigList.get(2);

This will fail if there aren't three in there, of course.

If, instead, you want to loop over all of the ArrayList<String>s that are in there and do something with them, it's

for (ArrayList<String> innerList : bigList) {
    // do something with innerList
}

This will now work regardless of how many there are in there. (Even if there are none in there, it'll still work, in the sense of not generating an error: the for loop won't execute at all.)

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.