Results 1 to 4 of 4
  1. #1
    tarik is offline Member
    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Default 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

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default 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!

  3. #3
    tarik is offline Member
    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Default Re: ArrayList refuses to set an initial capacity. please help!

    @ kevin. thank you. that was very helpful.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: ArrayList refuses to set an initial capacity. please help!

    Moved form Java Applets. What made you think this question belonged there?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. JApplet works in eclipse but refuses to show online
    By Reskaillev in forum New To Java
    Replies: 14
    Last Post: 09-10-2011, 01:36 PM
  2. Initial capacity of ArrayList
    By bugger in forum New To Java
    Replies: 12
    Last Post: 12-30-2009, 08:16 AM
  3. Limiting the capacity of a cell of JTable
    By rameshraj in forum Advanced Java
    Replies: 0
    Last Post: 03-24-2008, 02:20 PM
  4. Vector capacity
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-04-2007, 05:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •