TCLUG Development Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [TCLUG-DEVEL:40] Vector
erick@pagelab.net wrote:
>
> I am just starting to look online now, but if anyone knows, how do you
> use vector with primative data types e.g. int, double. Thanks.
>
You can't. That is one of the reasons behind the primitive type Wrapper
classes such as Integer, Boolean, Float. Vector can only contain
objects.
To load a Vector with int values:
Vector t_vector = new Vector(5);
for (int idx = 1; idx <= 5; idx++) {
t_vector.addElement(new Integer(idx));
}
To turn around and dump the Vector:
int t_vectorSize = t_vector.size();
for (int idx = 0; idx < t_vectorSize; idx++) {
System.out.println((Integer)t_vector.elementAt(idx));
}
Remember, Vectors are like arrays, they start at zero not 1.
--
Perry Hoekstra
Consultant
Talent Software Services
dutchman@mn.uswest.net
(612) 253-8461