In programming, one of the most commonly used data structures is Vector in Java. Arrays are static data structures that can linearly store data. Similarly, vector in java also store the data linearly, but they are not restricted to a fixed size. Instead, its size can grow or shrink as per requirement. The parent class is AbstractList class and is implemented on List Interface.
Before you start to use vectors, import it from the java.util.package as follow:
import java.util.Vector
Here is how a vector in java is declared:
public class Vector extends AbstractList
implements List, RandomAccess, Cloneable, Serializable
Here, V is the type of element which can be int, string, char, etc.
Like we access data members in arrays, we can do that in vectors, too, by using the element’s index. For example, the second element of Vector E can be accessed as E[2].
Some common errors made while declaring a vector in java:
#full stack development #java #vector #vector in java