This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Vectors question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Vectors question" Watch "Vectors question" New topic

Vectors question

shawn sandy

Joined: Jul 02, 2001
Posts: 12
Any ides why this only returns the last object in the vector 13 times (13 elements in the vector)?
for (int x=0; x < v2.size(); x++) {
//Object o = v2.elementAt(x);
System.out.println("Size of v2 ==> " + v2.size());
test2 = v2.size() - x;
System.out.println("Remaining size ==> " + test2);
applications = (Apps)v2.get(x);
line2 = applications.getName();
System.out.println( x + " V2 App Name ==> " + line2);
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Not from this code - it looks fine. How was this Vector created - and more importantly, loaded? Is it possible that it contains 13 references to the same single Apps object? I.e., did you call new Apps() once, or 13 times? And were all 13 separate references saved in the Vector?

"I'm not back." - Bill Harding, Twister
shawn sandy

Joined: Jul 02, 2001
Posts: 12
got it!
needed to insert into vector like so...
v2.addElement(new Apps(line.substring(0,indx),"root"));
jQuery in Action, 2nd edition
subject: Vectors question
Similar Threads
Help with Objects..
for loop logic problem
retrieve object from Vector
Guarenteeing G.C part