Java – vector and arraydeque classes
What is the difference between the vector and arraydeque classes? I read about the arraydeque class yesterday, and I used the vector class before
Solution
The basis is:
Vector implements Java util. List, which defines containers that allow index - based access to elements It also implements the interface randomaccess, which indicates to the user that the underlying representation allows fast (usually o (1)) access to elements
Arraydeque implements Java util. Deque, which defines a container and supports adding and deleting quick elements from the beginning and end of the container
Main differences:
>Vector supports the use of list Add (int index, e element) or list The overloaded version of addall (int index, collection C) adds elements to the middle of the container. > Vector supports the use of the remove method to delete elements from the middle of the container. > The set and setelementat methods of vector allow you to exchange elements in place (replace one object in vector with another, O (1) operation). > Added to the end of the vector is the allocated constant time Adding to the beginning or middle of a vector is a linear time operation (O (n)). > Arraydeque constant time (O (1)) to add / remove elements on the front and back of the container respectively. > Arraydeque does not allow you to specifically delete elements at a location in a container The various remove, removefirst, and removelast methods of the class allow you to delete elements more narrowly. > Arraydeque comes with methods that use classes, such as queues (PEEK, poll, add, addfirst) and similar stacks (offer, push, pop, peeklast, addlast), or both (so why is it a double ended queue). > Arraydeque does not support adding elements between double ended queues. > Vector has special listiterators, which allows you to get iterators starting from a specific location in the container, and also supports adding, deleting and setting elements Arraydeque's iterator does not support those additional methods. > Vector is a synchronization container, which means that it already contains code to perform synchronization / locking for a multithreaded environment For arraydeque, if you are multithreading access to the container, you must provide your own synchronization code Note that ArrayList is the unsynchronized counterpart of vector