• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Two dimensional Vector

 
Carl Pettersson
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I create a Vector with two dimensions? If so, how? I tried

but it didn't work (why else would I ask? ) Any tips?
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vectors contain objects. And since a Vector is an object, you can put a Vector inside a Vector. Does this help?
BTW, Vector is outmoded. It is slow and no longer recommended for use. Use a java.util.List instead (java.util.ArrayList is suitable for general use...).
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Joel pointed out, use ArrayList instead of Vector. If you need synchronization, you can always use Collections.synchronizedList() to create a List that synchronized.
Here is an example of a List that contains lists:
 
Carl Pettersson
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I really need to do is to have something like a Map, but for each entry, I need 6 values. In C++ I would have done it like this

But how would I do it in Java?
 
Carl Pettersson
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved the problem myself, found out that I could use ArrayList.add in ways I didn't know before
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carl,
If you're around, I'm curious what you figured out. So, what did you do exactly?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic