• 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

Default size of Vector and Arraylist

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

Like when we create ArrayList and Vector :

ArrayList a = new ArrayList();
Vector v = new Vector();

I have to ask that whats there by default initial capacity and load factor and at what stage they grow dynamically.

Thanks
Regards
Gaurav
 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The default capacity of a vector is 10 and after that it grows dynamically , about the capacity increment , question left to other ranchiies.
 
ram gaurav
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply , what about ArrayList , whats it default size.

I also want to know that at what point they decide to grow themself.

Thanks
Gaurav
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The below is the constructor of ArrayList and the default size of ArrayList is 10.

/**
* Constructs an empty list with an initial capacity of ten.
*/
public ArrayList() {
this(10);
}
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both ArrayList and Vector has default size of 10
unless u specify size in constructor while constructing them.
When you will add an element to an ArrayList or Vector then it will check wheather it's size is equal to it's capacity , and if it is then it will allocate 10 more spaces for elements if nothing is specified while constructing them, am not sure how much more spaces it will allocate if we will give size in constructor.
 
ram gaurav
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to you all
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic