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
iteratorthat are returned by both classes are fail-fast. TheEnumerationreturned 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.
Most Recent java Faqs
- How to uncompress a file in the gzip format?
- How to make a gzip file in Java?
- How to use Java String.split method to split a string by dot?
- How to validate URL in Java?
- How to schedule a job in Java?
- How to return the content in the correct encoding from a servlet?
- What is the difference between JDK and JRE?
Most Viewed java Faqs
- How to read input from console (keyboard) in Java?
- How to use HttpURLConnection POST data to web server?
- How to add BASIC Authentication into HttpURLConnection?
- How to Retrieve Multiple Result Sets from a Stored Procedure in JDBC?
- What are class variables in Java?
- What are local variables in Java?
- How to Use Updatable ResultSet in JDBC?