Sorry for this basic question but I cannot find anywhere how to initialed a vector with data.
Thanks.
Jacques
>Sorry for this basic question but I cannot find anywhere how to initialed a vector with data.
Whenever you need an introduction to something in Java, one place you
can usually get started is the Java glossary. It will give you an
overview and point you to more detailed information, and usually give
you a brief code sample of the basic operations.
http://mindprod.com/jgloss/jgloss.html
Just look up the word, in this case Vector.
http://mindprod.com/jgloss/vector.html
It will suggest you try ArrayList instead.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Jacques Chaurette - 15 Oct 2005 12:40 GMT
Thanks.
>>Sorry for this basic question but I cannot find anywhere how to initialed
>>a vector with data.
[quoted text clipped - 10 lines]
>
> It will suggest you try ArrayList instead.
> Sorry for this basic question but I cannot find anywhere how to
> initialed a vector with data.
In general, consider using ArrayList instead of Vector. It basically
does the same, but ArrayList is in general a faster.
Regarding the initialization of a Vector (or ArrayList):
Since Java 1.2:
Vector v = new Vector(Arrays.asList(<array-of-elements>));
or
Vector v = new Vector();
v.addAll(Arrays.asList(<array-of-elements>));
or a simple loop with calls to add().
In Java 1.5 you an also do (the stuff above also works):
Vector v = new Vector();
Collections.addAll(v, <array-or-varlist-of-elements>);
The 1.5 documentation claims this can be faster than Arrays.asList(). In
1.5. Arrays.asList() also allows a variable length list as argument.
/Thomas

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/