Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can you have an array of vectors

 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or an array of array's I think I just solved my problem but can you have an array of vectors?
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can. Did you get some error messages when you tried it or what?
 
Henry Wong
author
Marshal
Pie
Posts: 21122
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have an array of Vectors. You can have an array of array of Vectors. You can have a Vector of Vectors. You can have an array of array of Vectors of Vectors of array of array of Vectors...

Henry
[ March 10, 2006: Message edited by: Henry Wong ]
 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I go to declare the vector I get an error it says it is looking for ]? Here is the code

Vector POI[i] = new Vector();
POI is the array i is the counter. How do I declare the vector?
 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thankyou everyone I got it working!!!
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Henry Wong:
You can have an array of Vectors. You can have an array of array of Vectors. You can have a Vector of Vectors. You can have an array of array of Vectors of Vectors of array of array of Vectors...


What's this?

Vector v = new Vector();
v.add(v);
 
ak pillai
author
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a suggestion:

You can have a collection within a collection, But it is not a good coding practice to keep on tossing collections within collections. It makes your code hard to understand. This is analogous to storing items in pigeonholes without any labelling. To store items use value objects or data objects (as oppose to storing every attribute in an ArrayList or HashMap). Provide wrapper classes around your collection API classes like ArrayList, Hashmap etc
 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you never used a wrapper class before. What I need to do is create an unlimited amount of "Vectors"(Can be an array) with the vectors being different lengths each time it is run. I tried an array of vectors and ran into problems.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are not sure of the exact number of Vectors that you need, then you can use a dynamic structure like an ArrayList which can grow dynamically. (Also unless you have a compelling reason, you can use an ArrayList instead of a Vector).
 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I'm working with the arrayList and think it will work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic