ArrayList refuses to set an initial capacity. please help!
so here is the problem code block:
public class NewClass {
public static void main(String[] args){
int count= 9;
System.out.println(count);
ArrayList openingBracketIndex = new ArrayList(count);
ArrayList closingBracketIndex = new ArrayList(count);
System.out.println(openingBracketIndex.size());
System.out.println(closingBracketIndex.size());
}
}
and this is what gets printed out:
9
0
0
Re: ArrayList refuses to set an initial capacity. please help!
Capacity is totally different than size.
Think about an ArrayList as a box that can hold stuff, let's say jelly beans. Capacity is how big the box is. Size is how many jelly beans are in the box. If you have an empty box with a really big capacity, does that mean you automatically have more jelly beans? Nope. It just means you can fit more in there before switching to a bigger box.
Please read the API for ArrayList for more information.
Re: ArrayList refuses to set an initial capacity. please help!
@ kevin. thank you. that was very helpful.
Re: ArrayList refuses to set an initial capacity. please help!
Moved form Java Applets. What made you think this question belonged there?
db