Jump to content
  • Advertisement
Sign in to follow this  
gbizzle

[java] question about vectors

This topic is 4881 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 know that vectors have the ability to expand their size. Am I supposed to call a special add command to increase the size of a vector? In other words, can I tell the vector to insert some object at a specific location, and if the vector is not already that big, it will automatically stretch? hope that makes sense, thanks everyone

Share this post


Link to post
Share on other sites
Advertisement
All you need to know.

You can insert anywhere within the vector, from 'at the beginning' to 'at the end'. Items will get pushed back to make room for the insertion (e.g. if you insert at the beginning, then everything is shifted; if you insert at the end, then it just gets tacked on to the end and nothing else moves). The vector will resize itself as needed.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
the vector's add method will add an element to the end of the vector

example:

Vector myVector = new Vector();
myVector.add( new Integer(1) );

// the vector has one element

myVector.add( new Integer(2) );

// the vector now has two elements;

Share this post


Link to post
Share on other sites
Incidentally, Vector is depreciated - you should be using ArrayList instead (functionally the same, but unsyncronised). If you need a thread-safe ArrayList then you can wrap it in a thread-safe interface, which is described in the ArrayList docs.

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!