Java Collection Frame Work Series - Vector Class. How Vector class works internally?

preview_player
Показать описание
You can learn Java with me as the Java Programming language is being made easily. It would take a period of minimum three months and maximum 6 months to master Java. I would recommend you to watch all my videos to crack any software interviews that would require Java Programming language as a primary skill.

Vector:-
======
1. Vector is a class.
2. Vector implements List interface
3. Vector was introduced in the JDK1.0 version and it is a legacy class
5. By default, the initial capacity of Vector is 10.
6. Vector is an index based array where the insertion order is preserved.
7. Vector allows duplicate values
8 Vector does not follow sorting order.
9. Vector allows heterogenous elements for non-generic type.
10. Vector allows homogeneous elements for the generic type.
11. The Vector is resizable in nature. And its incremental capacity is as follows
INCREMENTALCapacity =(CurrentCapacity *2);
12. When you want to retrieve the data frequently, you can go for Vector. It is faster when you use it to retrieve the data.
13. Vector is synchronized in nature.
14. Vector is a thread safe.
15. Vector can be used in the Multithreaded environment
16. Vector performance is Low because it is synchronized.
17 . Vector ensures data consistency.(data couldn't be compromised)

Methods in Vector:-
===============
1. int capacity():
===============
This method is going to return the initial capacity of the Vector.
Please be informed that the capacity method is applicable only for Vector class. It is not available for ArrayList class.

2. void addElement(Object element):
=============================
The above method is used to add an element to the object and this method is very specific to the vector class.

3. public Object firstElement();
========================
The above method is used to return the value of the first element in the Vector object.
Please be informed that when you use the firstElement() on the empty vector object, it would throw the below exception.

========================
The above method is used to return the value of the last element in the Vector object.
Please be informed that when you use the lastElement() on the empty vector object, it would throw the below exception.
================================================
The above method is used to delete or remove the specific value in the Vector object.
If the element is removed, it will return true, or else it would return false.
6 .public void removeElementAt(int index);
====================================
The above method is used to delete or remove the specific value in on the respective index.
If you are passing an index that is not in the scope, you will get the below exception.

7 .public void removeAllElements();
=============================
The above method is used to delete or remove all the elements on the vector object

Constructors of Vector class.:-
========================
1. public Vector()
===============
The above constructor is used to keep the default capacity as 10.
2. public Vector(int capacity)
========================
Please be informed that the above constructor is used to set the user defined capacity.
3. public Vector(int capacity,int incrementalRatio)
========================================
Please be informed that the above constructor is used to set the user defined capacity as well as the incremental ratio.
Рекомендации по теме