Java Vectors

United States
January 21, 2009 9:47pm CST
Hey. Can someone explain to me what a Vector is in the Java language? The book i'm using to teach myself doesn't really explain a Vector. Since they didn't write a lot about them, i figured they weren't that important, but i'm seeing them in almost every program! So can someone please explain to me thoroughly what the heck a Vector is?!? Thanks a ton!
3 responses
• India
22 Jan 09
The Vector class provides the capabilities to implements a growable array of objects. foe example i am declaring vector v=new vector(5); after adding 4 th element the size of the vector is increases to double ie 10. so in this way the size of the vector is increases.It is synchrozised.so it is thead safe. It does not change the order of adding the elements.
• United States
23 Jan 09
Hmm....ok...so then after adding the 9th element...the array would switch to 20? I think I got it.... Does anyone have a simple program that demonstrates the use of Vectors? Thanks again!
• India
5 Apr 09
Vectors is growable and synchronized array. It is slow as compared to array. But always try to use vector because it is synchronized and size can be changed any time during development of program
• India
22 Jan 09
vectors are implemented with an array.When an array is full and an additional element is added, a new array must be allocated. import java.util.vector; or import java.util.*; *create a vector with default initial size Vector v = new Vector(); *create a vector with initial size Vector v = new vector(100); * To add elements to the end of a vector---- v.add(s); *To get elements from a vector use ListIterator. *Common vector methods---- v.add(o); v.add(i,o); v.clear(); v.contains(o); v.firstElement(i); v.get(i); v.listIterator(); etc.Look for it.