Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding elements to a vector

 
asha ganapathy
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
getPosition("Test1");
getPosition("Test2");
getPosition("Test3");

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.



Thanks,
Asha>
 
Campbell Ritchie
Sheriff
Pie
Posts: 50225
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 99
Flex Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, i figured out the problem. After i declared the vector as static my issue was resolved.

Thanks a lot,
Asha
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic