wood burning stoves
The moose likes Beginning Java and the fly likes Vector Values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Vector Values" Watch "Vector Values" New topic

Vector Values

Pol Appan
Ranch Hand

Joined: Aug 26, 2004
Posts: 144

I have a vector called v1 and I am loading values to the vector from a resultset.

--while ((getDet_hasData)&&(Repeat1__numRows-- != 0)) {
------- some code
where getDet is name of the resultset.

I am iterating the loop
Object vect;
String str = "";

for(int i=0;i<v1.size();i++) {
vect = v1.get(i).toString();
str = (String)vect;

setStrValues is a method in the bean and passing the value.

My problem is I am getting only the last value in my method, after the for loop I have other code to process. Since I am taking the value in the vector and I am iterating I should get all the values, rather than the last values.

What could be the problem and how can I solve it. Please help me

Any help is highy appreciated.



Never take anything for granted because you never know when you will lose it
Jeff Langr
Ranch Hand

Joined: May 14, 2003
Posts: 799
Looks like it should work, although it appears that the code could use some simplification. Send the other code if possible; use the UBB Code tags to help make it more readable.


Books: Pragmatic Unit Testing in Java, Agile Java, Modern C++ Programming with TDD, Essential Java Style, Agile in a Flash. Contributor, Clean Code.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
You're calling the setStr method with each value from the Vector, but each one replaces the prior value so you only see the last one. Maybe you could build up a single string with all the values in your loop and call setStr after the loop.

You'll have to work out the spaces and commas and such to make allValues look nice, but something like that oughtta work.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Pol Appan
Ranch Hand

Joined: Aug 26, 2004
Posts: 144
Thanks to everyone for pointing out the problem.

I will try.


I agree. Here's the link: http://aspose.com/file-tools
subject: Vector Values
It's not a secret anymore!