What is Vector ?

Vector is a dynamic array similar to ArrayList, Having two differences.
-Vector is Synchronized while ArrayList is not.
-It contains many legacy methods that are not part of Collection.

Vector was reengineered to extend AbstractList and implement List interface.
Vector also implements Iterable interface.
It is now generic class.
import java.util.*;
class demo1
public static void main(String[] args){
Vector hm=new Vector();
Enumeration e=hm.elements();

Vector is a legacy collection class which can be used to represent a group of objects.
• Introduced in 1.0 version. it is legacy class
• The underlying data structure is resizable or growable array.
• Insertion order is preserved
• Duplicates are allowed.
• Heterogeneous objects are allowed
• It is a implemented class for List interface
• null insertion is possible
• Vector class implements RandomAccess ,Serializable,Cloneable interfaces
• Best Choice if frequent operation is retrieval and worst choice if frequent operation is insertion or deletion in the middle.
• All methods present in Vector class are synchronized hence Vector class object is thread safe.

No comments:

Post a Comment