• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

size of arraylist

 
priyanaka jaiswal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
priyanaka jaiswal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jesper
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic