Results 1 to 4 of 4
- 10-09-2012, 08:15 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 2
- Rep Power
- 0
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
- 10-09-2012, 08:47 PM #2
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.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 10-09-2012, 09:02 PM #3
Member
- Join Date
- Oct 2012
- Posts
- 2
- Rep Power
- 0
Re: ArrayList refuses to set an initial capacity. please help!
@ kevin. thank you. that was very helpful.
- 10-10-2012, 07:34 PM #4
Similar Threads
-
JApplet works in eclipse but refuses to show online
By Reskaillev in forum New To JavaReplies: 14Last Post: 09-10-2011, 01:36 PM -
Initial capacity of ArrayList
By bugger in forum New To JavaReplies: 12Last Post: 12-30-2009, 08:16 AM -
Limiting the capacity of a cell of JTable
By rameshraj in forum Advanced JavaReplies: 0Last Post: 03-24-2008, 02:20 PM -
Vector capacity
By Java Tip in forum Java TipReplies: 0Last Post: 11-04-2007, 05:58 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks