Home  |   STIU  |   WOW  |   SCJP  |   SCDJWS   |   JEE FAQ  |   About US  |  

FAQ
  Java FAQ
  JSP FAQ
  Servlet FAQ
 

Advertisement

XyzWs Java FAQ:
What are the differences between Vector and ArrayList? Which one is better?


Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend


Previous Next vertical dots separating previous/next from contents/index/pdf Contents
Advertisement
XyzWs Java FAQ : What are the differences between Vector and ArrayList? Which one is better?

What are the differences between Vector and ArrayList? Which one is better?


  • Arraylist is not synchronized while Vector is.
  • Arraylist has no default size while Vector has a default size of 10. Both of them represent a "growable array".
  • Arraylist don't define any increment size while Vector does.
  • While the iterator that are returned by both classes are fail-fast. The Enumeration returned by Vector are not.

ArrayList is part of the Java collection framework. You should use it in most time to take advantages of Java collection framework. You probably won't need synchronization in most cases. It is easy enough to create a synchronized ArrayList using the following code:

Collections.synchronizedList(new ArrayList());

 

 

Notice: From ArrayList API Document:
The iterators returned by this class's iterator and listIterator methods are fail-fast: if list is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove or add methods, the iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.

 


Previous Next vertical dots separating previous/next from contents/index/pdf Contents

Support  | Feedback  | Help