A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Refactoring for Software Design Smells: Managing Technical Debt
this week in the
OO, Patterns, UML and Refactoring
Dynamically creating ArrayList inside a iterator
Joined: Mar 17, 2004
Aug 06, 2008 09:39:00
My requirement is this:-
I need to create "n" number of ArrayLists inside for loop dynamically n is based on a field value, which will also change.
Something like this:-
In the first iteration
firstIteration = new
and in the second iteration it should be like this...
SecondIteration = new
Please let me know How do I do this?
Thanks in advance,
Joined: Aug 10, 2005
Aug 06, 2008 10:31:00
Looks like you should use an array of ArrayLists. Create a new
and add it as the next element in the array at each iteration thru the for loop.
Joined: Dec 17, 2003
Aug 06, 2008 10:33:00
Or a collection, like a List. So you'd have a list of lists.
Joined: Dec 04, 2007
Aug 07, 2008 07:06:00
or you can use
iterationmap = new
iterationList = new
iterationmap.put("Iteration" + i , iterationList);
then you can get lists from map based on iteration no as key
Have you checked out
subject: Dynamically creating ArrayList inside a iterator
Iteration speed of Collections
generating unique numbers
Variable declaration inside loops - what happens?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015