Jump to content
  • Advertisement
Sign in to follow this  
jake_Ghost

[java] help with the java vector class

This topic is 4996 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i am a c++ programmer and i am used to the c++ vector class. With this java one, i cant get wat data is held in a certain index of the vector. The only thing that i have been able to do is vector.toString() and it returns the string data of every index. How do i get data from individual indexes. thx in advance jake

Share this post


Link to post
Share on other sites
Advertisement
thx man just wat i needed. I am using ready to program with java at my school and in the help they didnt mention anything about set or get lol.

Share this post


Link to post
Share on other sites


Iterator it = myvector.iterator();
while (it.hasnext()) {
MyData data = (MyData) it.next();
... do whatever you want with your data
}

that's if you want to iterate through every item in your collection. on the other hand, you can just do a .get(int) to return the index. I'd spend some time looking at the collections api. Get familiar with HashMaps as well. Make sure you are using the right tool for the job. Java collections can offer some amazing data processing capabilities once you learn their ins and outs.

Share this post


Link to post
Share on other sites
Just for the record, (so that people are aware of this),
you should traverse ArrayList and Vector classes with your basic
for-loop using the get and elementAt methods (because
these classes offer direct-index access), while you should
traverse for instance the LinkedList class using Iterators.

At least that's something to keep in mind if you want to
maximize performance-wise.

Share this post


Link to post
Share on other sites
Also don't used a syncronized list class if you don't have to.

ArrayList is allot faster than Vector because vector is syncronzied.

:-)

Share this post


Link to post
Share on other sites
Always favor the Collections Framework over Containers unless you absolutely need synchronization. Especially in games, Containers will kill performance.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!