This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Adding elements to a vector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Adding elements to a vector" Watch "Adding elements to a vector" New topic

Adding elements to a vector

asha ganapathy
Ranch Hand

Joined: Nov 03, 2006
Posts: 54
Hi All,

I have a method getPosition(String ignoreText) which is called from other methods.
I want to store the value of ignoreText at every invocation method getPosition in a vector

For e.g.: if getPosition is called this way

Then the vector should contain the values Test1, Test2, Test3

I have tried with the following code snippet, however the temp vector stores only the current value of ignoreText.
Please let me know how to do this.

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38075
Why are you declaring an Exception from that method? Why are you using Vector at all? There are better List implementations, eg ArrayList. Why does your method not return anything? Why would you want your method to return anything? Why are you using an ordinary for loop? Your method name looks very peculiar, and does not appear to reflect what the method does.

How are you invoking that method? Which object are you invoking the getPosition() call on?
Al Johnston
Ranch Hand

Joined: May 02, 2009
Posts: 99

Aside from the other issues that Campbell pointed out, my guess is that the reason you only get back whatever you passed for ignoreText is that you don't have a static invocation of your object. Without seeing how you are calling the object, it would seem that you are creating a new Vector each time you call so you're only getting back the latest new Vector and its content any time you call this method (just a guess).
asha ganapathy
Ranch Hand

Joined: Nov 03, 2006
Posts: 54
Yes, i figured out the problem. After i declared the vector as static my issue was resolved.

Thanks a lot,
jQuery in Action, 2nd edition
subject: Adding elements to a vector
Similar Threads
inheritance for Object class
forward referencing
protected field
Super class constructor calls derived class overridden method?