• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

loop through arraylist of arrays

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic