File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieving Vector Elements??

 
Rik Ny
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a Vector which stores random numbers, but I am having trouble retrieving them. How do I retrieve each individual element and print it to a screen??
P.S This vector stores numbers (int)
Cheers,Rik
 
Dave Vick
Ranch Hand
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rik
You want to use either get(index) or elementAt(index). Both of them take as an arguemnet the index of the element you want to get. To get all of the elements from a Vector this would do it for you:

This will just use what the default toString() implementation is for whatever object is stored in the Vector. To do something useful just cast it to whatever type of Object it is supposed to be and manipulate it then.
hope that helps
 
Dorothy Finkel-Laverty
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't store ints in a Vector. You can only store Objects. That might be contributing to your problem.....
Also, I would investigate the elements() method in the Vector class. It returns an Enumeration, and you can step through the list nicely. Check out the API for Vector and for Enumeration for the methods.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic