If I have an arraylist of arrays (each item in the arraylist is itself a one-dimensional array), how can I iterate over each element of each array contained in the arraylist?

Recommended Answers

All 4 Replies

I think I just figured out a way to do it:

                for (String[] s : employeeTotals) {
                    String empNum = s[0];
                    System.out.println(empNum);
                }

Is that a reasonable approach?

Good start, but inside the loop you have an array that you also need to loop through - ie you need 2 nested loops.

Something like this?

for (int i = 0; i < s.length; i++) {
    System.out.println(s[i];
}

Yes. Now combine those two pieces of code and you have your solution.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.