Click to See Complete Forum and Search --> : Help using insertElementAt


NoneOfThem
September 16th, 2009, 06:59 AM
Hi Friends!!!

I'm newbe, and I'm trying to pass some element since a string to a vector. And I don't know if I using insertElementAt correctly. You can see de code:

s is a string
vc is a vector

for (x= 0; x <n; x++) {
c = s.codePointAt(x);
vc.insertElementAt(c,x);
}

Thanks!!!

dlorde
September 16th, 2009, 08:06 AM
The code will compile and run, and the Vector will fill with the Integer character codes for the String characters, but why use Vector.insertElementAt when Vector.add would do just as well?

And what are you trying to achieve? Why put the characters into a Vector at all?

Also, you should use ArrayList instead of Vector, unless you have a particular reason for using Vector (e.g. multi-threading).

There are features that should not be used. There are concepts that should not be exploited. There are problems that should not be solved. There are programs that should not be written...
R. Harter