What is the difference between an array and a vector ?

What is the difference between an array and a vector ?

An array is simply a data structure that stores the similar types of elements with sequence of consecutively numbered. int a[]=new int[3]; 

 This will create an array of int of size 3. The size of the can\'t be increase once it is created.Vector is just like an array, but it is rescalable. That means we can increase or decrease the size of the vector. One most important thing about vector is that unlike array, vector can hold multiple types of element. Vector can be declared as:Vector v=new Vector();Vector provides the methods to manipulate the elements:v.add(\"Hello\");v.add(3);v.add(1,\"world!\");v.set(2,\"How are you!\");v.get(0);Use the vector if you want to store the multiple data types and don\'t know about the size.

Date:2012-01-09 00:00:00

Post Your Answers

User Email:

User Name:

Related Java Subjective Links

Java Subjective interview questions and answers for experienced and fresher