• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Adding elements to a vector

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Marshal
Posts: 79415
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 99
Postgres Database Flex Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
He's my best friend. Not yours. Mine. You can have this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic