I’m sorry this may seem a bit basic, but I can’t get my head into it today. I have this Vector and I want to fill it with the Results from a ResultSet which looks like:
column1, column2, column3, column4, column5
Vector<Vector<String>> myVector = new Vector<Vector<String>>();
while (rs.next()) {
String column1 = rs.getString(1);
String column2 = rs.getString(2);
String column3 = rs.getString(3);
String column4 = rs.getString(4);
String column5 = rs.getString(5);
myVector.put(column1, column2, column3, column4, column5);
Is this the correct way to do it?
TIA
http://docs.oracle.com/javase/7/docs/api/java/util/Vector.html
Vectorimplements theListinterface, so it hasadd(), notput(). AFAIK there are no collections in Java that support inserting elements with varargs, so you have to call it once per string:It would be better to use
ArrayListinstead ofVectorthough, unless you need synchronization (and even then, there are better ways to do it).Edit: the best (IMO) way to do it would be: