Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to convert a vector of vectors into a double array?
 
Similar Threads
Array
how to get data from a db into an array?
DefaultTableModel and Vector
toString()...
can you have an array of vectors