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 REST with Spring (video course) this week in the Spring 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"));
I agree. Here's the link:
subject: Vectors question
It's not a secret anymore!