This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Java in General and the fly likes Vector into Array Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Vector into Array" Watch "Vector into Array" New topic
Author

Vector into Array

J. Alenis
Greenhorn

Joined: Jul 12, 2004
Posts: 16
I would like to know if it is possible and how to do the following. I get a created Vector and I need to put it into an Array. Here are pieces of my program:

String [] columnName ={"sqlcode","sqlmessage","predicaat"};
String [] columnIO ={"out","out","in"};
String [] columnType ={"integer","varchar","varchar"};
Object [] columnValue ={"","","'nn>''123456789010'''"};

Vector in = new Vector();
for (int i=0; i<columnName.length;++i)
{ Vector row = new Vector();
row.addElement(columnName[i]);
row.addElement(columnIO[i]);
row.addElement(columnType[i]);
row.addElement(columnValue[i]);
in.addElement(row);
}

And I want all the elements in an array that will look like this:

String[][]SP_parms = {{"Out","integer","sqlcode","0"},
{"In","varchar","predicaat","'nn>''123456789010'''"},
{"Out","varchar","sqlmessage",""} };
Can somebody please help me.
Ta Ri Ki Sun
Ranch Hand

Joined: Mar 26, 2002
Posts: 442
If you can consider something else instead of the Vector you'd gain performance, but that aside.
calling "in.toArray" will result in an array of Vector objects, each with its own set of elements, now calling "row.toArray" on each of them will result in an Object[] again only this time it's your Strings, you can initialise a new array based on the number of rows you have, and loop to add its array.
Did I misunderstand you?
J. Alenis
Greenhorn

Joined: Jul 12, 2004
Posts: 16
The problem is that I receive the Vector like it is (I can't change annything) and I want these data to be moved into the table like I showed in my question.
Do I have to use StringTokenizer to get every element to move in a field in the table?
Ta Ri Ki Sun
Ranch Hand

Joined: Mar 26, 2002
Posts: 442
Originally posted by J. Alenis:
I want these data to be moved into the table like I showed in my question.
Do I have to use StringTokenizer to get every element to move in a field in the table?


no I don't see how StringTokenizer can be used here, you already have all the elements/tokens/Strings setup individually in that vector, why not just iterate through them?
Paul Misoni
Greenhorn

Joined: Jan 02, 2001
Posts: 16
Given vector "v" create an array "copyV" and copy the contents of your vector into it. Pretty straightforward stuff. Assuming, of course, that you want the contents of the array converted from objects to strings (which was the case for my application).

Hopefully this will at least provide some direction.


copyV = new String[v.size()];
v.copyInto(copyV);
[ July 12, 2004: Message edited by: Paul Misoni ]
J�rg Vater
Greenhorn

Joined: Mar 17, 2004
Posts: 10
try this:

[ July 13, 2004: Message edited by: J�rg Vater ]
J. Alenis
Greenhorn

Joined: Jul 12, 2004
Posts: 16
Thanks J�rg Vater,

This is what I really needed.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Vector into Array
 
Similar Threads
ResultSet not working
comparing two ResultSet
Help in XSL
Vector into Array
exception while creating JTables