my dog learned polymorphism*
The moose likes Java in General and the fly likes How to convert a vector of vectors into a double array? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to convert a vector of vectors into a double array?" Watch "How to convert a vector of vectors into a double array?" New topic
Author

How to convert a vector of vectors into a double array?

tien liu
Greenhorn

Joined: Dec 13, 2002
Posts: 18
Hi,
Could someone please give me pointers on how to convert a vector of vectors into a two-dimensional array?
Each sBank and dBank consists of a name and a number. Output example from the method below:
parseBankPairNames = [[SEAT, 48, SANF, 47, SALT, 46,], [BOST, 3]]
public Vector parseBankPairNames(String sBank, String dBank {
Vector origin = parseBankName(sBank, dBank),
destin = parseBankName(dBank, sBank);
Vector v = new Vector();
v.addElement(origin);
v.addElement(destin);
System.out.println("parseBankPairNames = " + v.toString());

return v;
}
}
Thanks for your help.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Try this:

Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Garrett Smith
Ranch Hand

Joined: Jun 27, 2002
Posts: 401
If the depth is variable (sometimes 2d, sometimes 3d), you can use a recursive solution like this.

There's probably a more efficient way to do it with a loop construct. Recursion just seemed natural here.


comp.lang.javascript FAQ: http://jibbering.com/faq/
tien liu
Greenhorn

Joined: Dec 13, 2002
Posts: 18
Hi Michael,
Thanks for the code. It works great for converting a vector of vectors into a double array.
Could you tell me what part of the code to modify for converting a vector (with two values each row) into a double array?
output example: [[BOST, 3]]
Thanks.
tien liu
Greenhorn

Joined: Dec 13, 2002
Posts: 18
Hi Michael,
Please ignore my last question. The code you sent me works great.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Good, because I've spent the last couple of hours trying to understand what you wanted . I'm glad it all works
Michael Morris
 
Don't get me started about those stupid light bulbs.
 
subject: How to convert a vector of vectors into a double array?