| Author |
Default size of Vector and Arraylist
|
ram gaurav
Ranch Hand
Joined: Mar 29, 2006
Posts: 208
|
|
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
Joined: Apr 05, 2004
Posts: 145
|
|
|
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
Joined: Mar 29, 2006
Posts: 208
|
|
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
Joined: Jun 21, 2006
Posts: 96
|
|
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
Joined: Dec 14, 2005
Posts: 49
|
|
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.
|
Warm Regards<br />Ajit Amitav Das<br />SCJP 1.5
|
 |
ram gaurav
Ranch Hand
Joined: Mar 29, 2006
Posts: 208
|
|
|
Thanks to you all
|
 |
 |
|
|
subject: Default size of Vector and Arraylist
|
|
|