• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Vectors question

 
shawn sandy
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
shawn sandy
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it!
needed to insert into vector like so...
v2.addElement(new Apps(line.substring(0,indx),"root"));
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic