when it comes to the difference in ArrayList and Vector, it is said that Vector is synchronised while ArrayList not.. But still i have seen the implementation of ArrayList in Web Applications, though it is preferred to use Vector in multi-threaded applications. How do we achieve synchronization in such applications by using arraylist??
The major reason for using ArrayList is the performance factor. If we use Vector then the app becomes slow bcs Vector is synchronized and canot be accessed by multiple threads concurrently. The point of confusion for you is "in web apps why do we use ArrayList even though we have multiple threads accessing the ArrayList ? " and the answer is as stated above. But if there is a possiblity that multiple threads will try to modify(write) the value of an arrayList (rather than just accessing(read)it) , then it's better to use a Vector or synchronize the block of code where the modification is done ,which ever is relevent to the situation.
You never need to Vector/Hashtable, you can get the same benefit using ArrayList/HashMap if you synchronize the methods that access these objects. Therefore, these classes give you more flexibility over the original implementations.
It doesn't say that Vector or Hashtable are deprecated; both classes will still work. If you look at some other classes, however, you will find them marked as deprecated, eg StringTokenizer, which it specifically describes as legacy code (but it will still work), and methods like Thread.stop, where there are dire warnings against using it at all.
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database