Hi Hosh Nasi,
Welcome to the Ranch!
Firstly I should point out that java.util.Vector has effectively been superseded by java.util.ArrayList since the advent of the Collections Framework in
Java 1.2. Best advice going forward is to use ArrayList. Vector is really only there for backward compatibility.
Having said that you access a Vector as follows:
You would iterate over a Vector as follows:
Since Java 1.2 Vector has implemented the List interface, so you can also use that to access its elements (confusing, huh?):
You can also iterate as follows:
The thing is there's not much point you learning that as it's largely history. You certainly shouldn't do it going forward.
Here's what
you should use: ArrayList:
You can iterate as follows:
Notice that the methods for manipulating and iterating over a Vector (2nd pair of examples) and an ArrayList are identical. This is because they both use the List and Iterator interfaces. Cool, huh?
I think you may benefit from taking a look at
Sun's Collections Tutorial.
Jules
[ September 11, 2004: Message edited by: Julian Kennedy ]