wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Collection APIs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Collection APIs" Watch "Collection APIs" New topic
Author

Collection APIs

vijay shanker
Ranch Hand

Joined: Oct 26, 2007
Posts: 88
What is difference between Vector and List in java.util package.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42058
    
  64
List is an interface that is implemented by a number of classes with differeny characteristics (e.g. ArrayList and LinkedList). A more proper comparison would be between Vector and ArrayList. The major difference is that all methods of Vector are synchronized, making it ready to use in multi-threaded code. ArrayList's methods aren't synchronized, making it generally faster. In most cases you should use ArrayList instead of Vector.


Ping & DNS - my free Android networking tools app
vijay shanker
Ranch Hand

Joined: Oct 26, 2007
Posts: 88
thanks Ulf Dittmer.


So, from ArrayList and Vector whatever i use i will get same result barring quickness of ArrayList?

May you make a genral picture of collection APIs for easy understanding as i am feeling lost is the api.


How to decide which class should be synchronized?
Mintoo kumar
Ranch Hand

Joined: Aug 21, 2007
Posts: 61
Vector and Hashtable are the very old datastructure in java.in other words you can these are the two data structure earlier java had. So ,keeping in mind it to use with the mulit-threaded enviornment ,methods of both has been made synchronized( you can exlpore the API). As we know ,synchronization always cause the performance hit.There are sometimes while devloping software where you do not need synchronization there comes the use of ArrayList(depends according to situtation),which gives you linear searching,methods of arraylist are not synchronized.for small size database or elements you can not realise the difference.Both behaves the same way. But genrally it is discourage to use the vector where you do not need synchronization. If you want you can synchronize the methods of Arraylist ,by using the Collections class where no. of utility methods has been given.you can use it according to your need. Hope the above answer will be helful for you anyway.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42058
    
  64
So, from ArrayList and Vector whatever i use i will get same result barring quickness of ArrayList?
Yes, provided that multi-threadedness makes no difference.

May you make a genral picture of collection APIs for easy understanding as i am feeling lost is the api.

You might want to work through the Sun Java Tutorial chapter on Collections.

How to decide which class should be synchronized?

The API designers decided that not all Vector uses needed to be thread-safe, so they gave the developers a choice by providing a class that isn't thread-safe by default. (Of course, using the Collections classes has other benefits as well.) ArrayList can still be used in multi-threaded environments; it's just the developers need to decide which accesses need to be synchronized.
vijay shanker
Ranch Hand

Joined: Oct 26, 2007
Posts: 88
thanks you both,


now i feel great thinking of collection.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Collection APIs