Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
tien liu
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:

Michael Morris
 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael,
Please ignore my last question. The code you sent me works great.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good, because I've spent the last couple of hours trying to understand what you wanted . I'm glad it all works
Michael Morris
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic