In this topic, you will learn about, What is a vector? How is it different from an array?
Vector is a class allow to contain various different types of values. vector use util. package for declaration and it represents the same as an array but vector provide various functions and method for different operations.
How to create vector:
Vector <object> =new vector (size);
Eg:-vector v=new vector(5);
Difference between an Array And Vector:
|It is a collection of homogeneous elements.||It is a collection of heterogeneous elements.|
|Array index starts with zero.||The vector index starts with zero.|
|It can be access element by using index||It accesses elements by using functions.|
|Array size must be declared at the time of creation.||Vector size can be defined at any position.|
|An array is used to copy contents.||Its element can be copy and store in an array.|
Syntax:-<data type><array name>[size];
Eg:- int arr;
Arr =new int ;
Eg:- vector v;
Here is the topic, Applet Program to Demo Vector Class.
Comment below if you have queries related to the above article What is a vector? How is it different from an array?