Java - ArrayList - Get a value from an Array of array
I save some values from database using this function (i've been开发者_开发技巧 replaced Vector, because is deprecated) :
// database function
public ArrayList<String[]> selectQuery(String query) {
ArrayList<String[]> v = null;
String [] record;
int colonne = 0;
try {
Statement stmt = db.createStatement();
ResultSet rs = stmt.executeQuery(query);
v = new ArrayList<String[]>();
ResultSetMetaData rsmd = rs.getMetaData();
colonne = rsmd.getColumnCount();
while(rs.next()) {
record=new String[colonne];
for (int i=0; i<colonne; i++) record[i] = rs.getString(i+1);
v.add((String[])record);
}
rs.close();
stmt.close();
} catch (Exception e) { e.printStackTrace(); errore = e.getMessage(); }
return v;
}
// here i print the result, after call that function
ArrayList db_result=null;
db_result=mydb.selectQuery("SELECT titolo, user, date FROM articles WHERE category='1' ORDER by ID ASC");
int i=0;
while (i<db_result.size() ) {
affitta_3.createLabel().setLabel(db_result.get(i)[0]);
affitta_3.createLabel().setLabel(db_result.get(i)[1]);
affitta_3.createLabel().setLabel(db_result.get(i)[2]);
affitta_3.createLabel().setLabel(db_result.get(i)[3]);
i++;
}
So, i save many String-array in an array. Now, how can I get (for example) the 4° value from the 2° Array String?
Why are you bothering to clone the string array when nothing else will have a reference to it?
Anyway, you'd get at the string using:
String value = v.get(1)[3];
(assuming that v
is of type List<String[]>
or something similar).
精彩评论