programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

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

tien liu
Greenhorn
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();
System.out.println("parseBankPairNames = " + v.toString());

return v;
}
}

Michael Morris
Ranch Hand
Posts: 3451
Try this:

Michael Morris

Garrett Smith
Ranch Hand
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.

tien liu
Greenhorn
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
Posts: 18
Hi Michael,
Please ignore my last question. The code you sent me works great.

Michael Morris
Ranch Hand
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

 It is sorta covered in the JavaRanch Style Guide.