• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

loop through arraylist of arrays

 
J Brewer
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just can't seem to get my head around how to iterate through an arraylist of arrays.

I get as far as, for example:
details - arraylist of object Details that has a field named Data, which is also an arraylist. Data stored arrays in the arraylist.
count - an outer loop i'm using to iterate through all details arraylists.


for (int i=0; i < details.get(count-1).getData().size(); i++){




this is as far as i get. Any suggestions?


Thanks,
[banghead]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65124
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your problem is that you're biting off more than you can chew...

Let's take it one step at a time.

First, we know that we have a List of Detail objects, so let's set up a loop to iterate through those:



Now, inside the loop we have each detail object available, one at a time.

We also know that each detail contains a List of its own, so in order to iterate through that list we set up another loop:



You didn't say what type of object was in the data List, so I used "Whatever".

That help?

The upshot is, when you have nested lists/arrays, you need nested loops to iterate through them.
[ November 13, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65124
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, if you are using JDK 1.5, the syntax can be considerably simplified through use of the new style of for loop.
 
J Brewer
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I'll give it a try. I figured it would be nested loops but for some reason I couldn't get my head around it yesterday.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic