This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Java in General and the fly likes vector and array list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "vector and array list " Watch "vector and array list " New topic
Author

vector and array list

vishnu hiranamayee
Greenhorn

Joined: Feb 23, 2006
Posts: 17
Hi
Both vector and arraylist are growable arrays and the differnece is vector is synchronized and arraylist is not synchronized.
How is synchronization done in vectors.
Mani Ram
Ranch Hand

Joined: Mar 11, 2002
Posts: 1140
Originally posted by vishnu hiranamayee:
How is synchronization done in vectors.


In the same way you synchronize your classes.
The set() method in Vector looks like this


Where as the set() method in ArrayList reads


Got the difference?


Mani
Quaerendo Invenietis
vishnu hiranamayee
Greenhorn

Joined: Feb 23, 2006
Posts: 17
public synchronized Object set(int index, Object element) {}

But in the API of vectors only
Object set(int index, Object element)
is given .

if we give
public synchronized Object set(int index, Object element) {}
then arraylist will also be synchronized?
Then what is the differnece between vector and arraylist?
vishnu hiranamayee
Greenhorn

Joined: Feb 23, 2006
Posts: 17
public synchronized Object set(int index, Object element) {}

But in the API of vectors only
Object set(int index, Object element)
is given .

if we give
public synchronized Object set(int index, Object element) {}
then arraylist will also be synchronized?
Then what is the differnece between vector and arraylist?
ak pillai
author
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
Yes . Java Collections Framework remedies these problems and offers a number of advantages over using no framework or using the Vector and Hashtable


This article might help.

http://www.javaworld.com/javaworld/jw-11-1998/jw-11-collections.html


java j2ee job interview questions with answers | Learn the core concepts and the key areas
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: vector and array list