File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes ArrayList & Vector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ArrayList & Vector" Watch "ArrayList & Vector" New topic
Author

ArrayList & Vector

Amrita Puja
Greenhorn

Joined: Sep 27, 2006
Posts: 10
Hi.

Difference between arraylist and vector is that, arraylist is synchronized where as vector is synchronized, in arraylist when the data added increases array size will increase, but in vector when initial size should be specified, if we add more data to it, it will double the size giving more allocations.

According to my knowledge, these are the diffrences i know.

Please tell me these differences are correct or not. If more differences are there, post those answers.

If arraylist is not synchronized, how we can do it synchronized.

If already list is there, what is the need of arraylist.

Thankyou.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Not an advanced question. Moving...


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Difference between arraylist and vector is that, arraylist is synchronized where as vector is synchronized
False, ArrayList is unsynchronized.
in arraylist when the data added increases array size will increase, but in vector when initial size should be specified, if we add more data to it, it will double the size giving more allocations.
This depends on how you construct the Vector. Check java.util.Vector #capacityIncrement
If arraylist is not synchronized, how we can do it synchronized.
List<E> synchronizedList = Collections.synchronizedList(new ArrayList<E>());
If already list is there, what is the need of arraylist.
List is an interface, ArrayList is a basic implementation of this interface.
[ October 12, 2006: Message edited by: Bauke Scholtz ]
Makarandp Parab
Greenhorn

Joined: Sep 26, 2006
Posts: 6
Hi As you said, the differences you have given about Arraylist and Vector are perfect. Now about you queries If arraylist is not synchronized, how we can do it synchronized.?

If you want to make arraylist synchronized, you should use Collections.synchronizedCollection(Collection c) method or you can use Collections.synchronizedList(List list) method in the Collections class.

If already list is there, what is the need of arraylist? Amrita, check the API[java.util]. List is an interface which sets the rule where as Arraylist implements the List interface.

Regards Makarand
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi ranchers,


Vector came first. It was already introduced into Java in version v1.2.
Due to this, Vector still has the old method names like addElement. This method identifier (and the like) is/are not found in ArrayList.


Yours,
Bu.


p.m., hey, Makarandp, do you know, your member number is a prime?


all events occur in real time
Makarandp Parab
Greenhorn

Joined: Sep 26, 2006
Posts: 6
Hi Burkhard Hassel
"hey, Makarandp, do you know, your member number is a prime?" - i didn't get what you want to say. Can you come back please.

Regards
Makarand parab
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
A prime number is divideable to a round number by 1 or itself only. Your member number 134857 is such one.
Also see http://en.wikipedia.org/wiki/Prime_number

Nothing to do with yourself
[ October 12, 2006: Message edited by: Bauke Scholtz ]
Makarandp Parab
Greenhorn

Joined: Sep 26, 2006
Posts: 6
ooohhhh
He was talking of "Member # 134857". Sorry i really didn't get that.
Good observation.

Regards
Makarand Parab
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ArrayList & Vector
 
Similar Threads
ArrayList vs Vector
Differences between vector and arraylist
what is the use of different collections..
ArrayList & Vector
what is the difference between arrays,vector and Array List?