wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Difference between vector and array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Difference between vector and array" Watch "Difference between vector and array" New topic

Difference between vector and array

Nadia Waring

Joined: Jul 04, 2000
Posts: 1
What is the difference between a vector and an array?
deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
hello nadia,
both array and vectors are use to store data . the difference lies here....
1)the size of array need to be declared in advance.
2)once declared array can't grow in size.
3)array can store primitive data types.like
1) no need to declare the size of
vector. u may give its size & u may not.
2) Vector can always grow in size if u start adding more element to it than ur declared size.
3) Vector can store only object references. storing primitive data types is not possible in case of vectors.

[This message has been edited by deekasha gunwant (edited July 04, 2000).]
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
u can store primitives only by using the Wrapper classes.
also u can add an element in a given position and also in the end in a vector. Adding an element at a given position pushes an existing element below thus increasing the size. This is not possible in an array as the old values are replaced by the new one.
same is the case for removing of elements. In a vector removing an element reduces the size of the vector pushing the older values up by one position.
A vector is synchronized, an array is not
the example shows this.
import java.util.*;
class demo
public static void main(String[] args)
Vector a=new Vector();
Enumeration z=a.elements();
int x[]=new int[2];
System.out.println(x[1]);// contains 0 not 8


[This message has been edited by rahul_mkar (edited July 10, 2000).]
I agree. Here's the link: http://aspose.com/file-tools
subject: Difference between vector and array
Similar Threads
What is difference between ArrayList and vector?
Vector vs. Array
i cant understand this code
Question in Collection?
what is the difference between arrays,vector and Array List?