This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
How to convert a vector of vectors into a double array?
tien liu
Greenhorn
Joined: Dec 13, 2002
Posts: 18
posted
0
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
posted
0
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
posted
0
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.
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
posted
0
Hi Michael, Please ignore my last question. The code you sent me works great.
Michael Morris
Ranch Hand
Joined: Jan 30, 2002
Posts: 3451
posted
0
Good, because I've spent the last couple of hours trying to understand what you wanted . I'm glad it all works Michael Morris