This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Default size of Vector and Arraylist

 
ram gaurav
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • 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
 
tanu dua
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Sujittt Tripathyrr
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • 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);
}
 
Ajit Amitav Das
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks to you all
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic