Results 1 to 3 of 3

Thread: ArrayList size

  1. #1
    Join Date
    Oct 2014
    Posts
    2
    Rep Power
    0

    Post ArrayList size

    ArrayList l = new ArrayList();
    System.out.println(l.size());

    Hi,
    Can someone tell me " when I running the above code in eclipse the console show me the result as "0". So how to rectify this code to find default size as 10.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: ArrayList size

    Whoever told you that the default size is 10?

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

  3. #3
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    10

    Default Re: ArrayList size

    Hi Bimal, welcome.

    Quote Originally Posted by Java Arraylist API
    ArrayList()
    Constructs an empty list with an initial capacity of ten.

    public int size()
    Returns the number of elements in this list.
    ArrayList (Java Platform SE 8)
    You seem to be confusing initial capacity (10) with the number of elements in the list (0).

    Regards.

Similar Threads

  1. Replies: 1
    Last Post: 02-19-2012, 02:52 PM
  2. ArrayList size error
    By wepwep in forum New To Java
    Replies: 9
    Last Post: 03-29-2011, 10:57 AM
  3. ArrayList size while adding or setting
    By GaBuG in forum New To Java
    Replies: 2
    Last Post: 01-02-2011, 07:31 PM
  4. ArrayList pointer size java
    By senorbum in forum Advanced Java
    Replies: 6
    Last Post: 05-20-2010, 10:44 AM
  5. Limiting size of ArrayList
    By ravian in forum New To Java
    Replies: 3
    Last Post: 01-29-2008, 07:37 AM

Posting Permissions

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