• Post Reply Bookmark Topic Watch Topic
  • New Topic

Looping through Multiple ArrayList's  RSS feed

 
Preet Rams
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following program:



What im trying to do is this: I get the value of time, cpu and state from the user. find the match in the arraylist for the corresponding values, then I want to loop through the arraylists for only those values which match the 'state'. All the ArrayLists are of same size and contain values corresponding to each other at any given index. How can I do this?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to loop through the arraylists for only those values which match the 'state'

I don't believe you can.

You have to loop through the entire arraylist. What you can do is test each element to find to see if it is one you care about, and then do whatever you want to do with it.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All the ArrayLists are of same size and contain values corresponding to each other at any given index.

In that case you'd be better off having a class that encapsulates the different attributes (eg cpu, state etc) and then have a single ArrayList which contains instances of that class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!