• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ArrayList constructor

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




Hi everyone in the above code My doubt is


public ArrayList(int initialCapacity)
Constructs an empty list with the specified initial capacity.



but if I invoke size then it gives 0..???
here I hav created arraylist with initial
size 2 but why it gives size 0???


2>

public ArrayList()
Constructs an empty list with an initial capacity of ten.


but here also if I invoke size then it gives 0 as output..



please tell me whats the real meaning of it???

thnks in advance

with regards
 
Ranch Hand
Posts: 258
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ArrayList is backed by array.
Capacity and size are different, capacity means total space while size means occupied space.
If there is insufficient capacity, a new array would be created to hold the values which is useful if you know the capacity to avoid creating new array.
 
reply
    Bookmark Topic Watch Topic
  • New Topic