Maps - Urgent

Hi I have the values of maps which is stored in outer...My problem is that I dont know how to set the size of the arraylist outer as it depends on the content of the maps..pls help


ArrayList<ArrayList<Double>> outer;
ArrayList<Double> inner;
outer=new ArrayList<ArrayList<Double>>(????);
for(int i = 0;i < maps.size();i++)
{
Iterator<Map.Entry<BigDecimal,Integer>> iter = maps.get(i).entrySet().iterator();
            
while(iter.hasNext())
{
Map.Entry<BigDecimal,Integer> e = iter.next();
System.out.printf("Year = %d, value = %f, frequency = %d\n", i, e.getKey().doubleValue(), e.getValue());
               

double a=((double)e.getValue()/(double)5)*100;
inner=new ArrayList<Double>(4);
outer.add(inner);
inner.add((double)i);
inner.add(e.getKey().doubleValue());
inner.add(e.getValue().doubleValue());
inner.add(a);
                 
Jasbir21Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
You don't need to set the size of outer if you can't
0
CEHJCommented:
outer=new ArrayList<ArrayList<Double>>();

will do if size unknown
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mayank SAssociate Director - Product EngineeringCommented:
You should not set the size of collections, BTW.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Jasbir21Author Commented:
Thanks a lot :-)..
0
Jasbir21Author Commented:
I have another question on maps too,pls look at that ..
0
CEHJCommented:
:-)

>>You should not set the size of collections, BTW.

What makes you say that?
0
Mayank SAssociate Director - Product EngineeringCommented:
Basically, you want the collection to expand. You can set the initial size or by how much you want it to expand by, but ultimately you want it to remain growable. I don't think you can set the final limit on the size of a collection. I'd use an array if I want fixed size.

>> inner=new ArrayList<Double>(4);

Doesn't mean that the size will remain 4. The initial size will be 4, but if there are expansions required, they will be done. So effectively, you can just live with inner = new ArrayList<Double> () ;
0
CEHJCommented:
>>but ultimately you want it to remain growable.

Not necessarily.

>>I'd use an array if I want fixed size.

That may not be convenient or even possible
0
Mayank SAssociate Director - Product EngineeringCommented:
I haven't come across a case in production where I wanted to keep a collection fixed size, but at least in this case I don't think that is required :)
0
CEHJCommented:
Well it's sometimes required, which is why the ctor x(int) is provided, together with making it possible to optimise allocations
0
Mayank SAssociate Director - Product EngineeringCommented:
The ctor is for initial size, right? But if you add beyond those many items, expansion will happen....?
0
CEHJCommented:
Expansion will happen, yes
0
Mayank SAssociate Director - Product EngineeringCommented:
That's what I meant :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.