aspose file tools
The moose likes Java in General and the fly likes difference between ArrayList - Vector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "difference between ArrayList - Vector" Watch "difference between ArrayList - Vector" New topic

difference between ArrayList - Vector

Sofie Deceuninck

Joined: Feb 20, 2004
Posts: 11
I want to make an array where the size is variable.
What's the difference when I use an ArrayList or a Vector?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189

Hi Sofie,
Vector is older; ArrayList was introduced with JDK 1.2. The main difference is that Vector's methods are synchronized, while ArrayList's are not. Synchronized methods effect how the class will behave in a multi-threaded program. They make the class "safer," but at the expense of a little performance.
Most new code should use ArrayList. If you need a synchronized list, you can use Collections.synchronizedList(myArrayList). There's little reason to use Vector in new code (except when you need one to pass to an older method that wants a Vector as an argument.)
I'm going to move this to the Java in General (Intermediate) forum, where this discussion would be more at home.
[ February 20, 2004: Message edited by: Ernest Friedman-Hill ]

[Jess in Action][AskingGoodQuestions]
It is sorta covered in the JavaRanch Style Guide.
subject: difference between ArrayList - Vector