Thursday, June 7, 2007

When to use Vector? When to use ArrayList?

* ArrayList is faster when compared to Vector since ArrayList is unsynchronized. So, if the List will be modified by only one thread, use ArrayList. If the list is a local variable, you can always use ArrayList. *If the List will be accessed by multiple threads, always use Vector, otherwise you should take care of synchronization manually.
1. Use Vector if there are multiple threads and ArrayList if there is only a single thread. 2. Use Hashtable if there are multiple threads and HashMap if there is only a single thread. 3. Use StringBuffer if there are multiple threads and StringBuilder if there is only a single thread.

0 Comments: