wood burning stoves 2.0
The moose likes Beginning Java and the fly likes Two dimensional Vector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Two dimensional Vector" Watch "Two dimensional Vector" New topic

Two dimensional Vector

Carl Pettersson
Ranch Hand

Joined: Sep 09, 2003
Posts: 73
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

Joined: Aug 20, 2001
Posts: 1824

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...).

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
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

Joined: Sep 09, 2003
Posts: 73
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

Joined: Sep 09, 2003
Posts: 73
I solved the problem myself, found out that I could use ArrayList.add in ways I didn't know before
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
If you're around, I'm curious what you figured out. So, what did you do exactly?

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link: http://aspose.com/file-tools
subject: Two dimensional Vector
jQuery in Action, 3rd edition