wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes size of arraylist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "size of arraylist" Watch "size of arraylist" New topic
Author

size of arraylist

priyanaka jaiswal
Ranch Hand

Joined: Jun 03, 2011
Posts: 79
Hi All,


By default the size of arraylist is 10,but when we add one element to arraylist what will be its size?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

priyanaka jaiswal wrote:By default the size of arraylist is 10

No. Its initial capacity is 10 by default, but its size will be 0.

Size is the number of elements that the ArrayList contains.

Capacity is the number of elements that the ArrayList reserves space for. Note that this is an implementation detail of ArrayList - you don't normally need to know this to be able to use an ArrayList. It's just how ArrayList is implemented so that works efficiently.

If you add an element to an ArrayList, its size will grow by 1. So if you have an empty ArrayList (with size 0) and you add an element, its size will be 1.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
priyanaka jaiswal
Ranch Hand

Joined: Jun 03, 2011
Posts: 79
Thank you Jesper
 
 
subject: size of arraylist
 
Similar Threads
programming to the interface
generic method
about random.next int();
Multiple ArrayList
getting the next element from a arraylist