Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

vector and array list

 
vishnu hiranamayee
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
vishnu hiranamayee
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic