Another Java question, sorry guys. I am trying to do something similar to the below dynamically.
The above code works fine, however, it's not the solution I'm looking for. Ideally I would like to be able to be able to load the Object[][] array dynamically depending on how many results are contained in ArrayList which is returned by my database query method.
I've been trying variations of the code below casting to and from String[] and Object[] and using ArrayList.toArray(), in the vain hope something will work.
When the Object[][] from the above is passed to dpTest(String[] Quotes) I get an ArrayIndexOutBounds 1 (the number 1 corresponds to the number of arguments in the method declaration).
I take it I'm not passing the information correctly, though, when I output using Arrays.toString(array) and Arrays.deepToString(array) the contents are the same or similar.
Code:
String[] field1 = { "Liam", "23", "M" };
String[] field2 = { "Sarah", "32", "F" };
String[] field3 = { "Thomas", "45", "M" };
Object[][] retObjArr = { { field1 }, { field2 }, { field3 } };
[/quote]The Object[][] is passed to a method that uses the elements in the String[]'s as test data.
[quote] @Test(dataProvider = "DP1")
void dpTest(String[] fields) {
System.out.println("Firstname: " + fields[0]);
}
I've been trying variations of the code below casting to and from String[] and Object[] and using ArrayList.toArray(), in the vain hope something will work.
Code:
ArrayList<String[]> listRows = null;
try {
listRows = myDb.getRows("SELECT * FROM Quotes;");
assert listRows.size() > 0;
} catch (Exception e) {
System.err.println("No results returned.");
}
Object[][] Rows = new Object
[listRows.size()][];
for (int i = 0; i < listRows.size(); i++) {
String[] tempRow = listRows.get(i);
Rows[i] = tempRow;
}
return (rows)
I take it I'm not passing the information correctly, though, when I output using Arrays.toString(array) and Arrays.deepToString(array) the contents are the same or similar.
Last edited: