This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes default size of vector and arraylist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "default size of vector and arraylist" Watch "default size of vector and arraylist" New topic

default size of vector and arraylist

yash Vi
Ranch Hand

Joined: Jul 17, 2005
Posts: 41
I know the basic difference that vector is synchronised and arraylist is not.There is some difference in the default size and the way it expand itself when it becomes full.can someone help me understand the same

Thanks for your reply and time.<br />Windows 2000,j2sdk1.4.2_08
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189

They do use a different algorithm for growing the array. Vector uses the classic multiply-by-two algorithm -- every time the array grows, it doubles in size. From a theoretical standpoint, this has near-optimal performance -- but it uses too much memory. I believe ArrayList uses a more moderate grow-by-50% rule; the performance in real applications is basically the same, and it uses less memory.

[Jess in Action][AskingGoodQuestions]
yash Vi
Ranch Hand

Joined: Jul 17, 2005
Posts: 41
Thanks for the update.wot is the size when it is initially created using their default constructor
Stuart Gray
Ranch Hand

Joined: Apr 21, 2005
Posts: 410
According to the source it is 10 in both cases.
I agree. Here's the link:
subject: default size of vector and arraylist
It's not a secret anymore!