Most efficient way to access a Column in a DataTable.

Hey guys and girls, im sorry for the basic / silly question.

If i have a BufferedDataTable, say with 4 columns and 10 rows. What would be the most efficient way to convert the 3rd column into an array.

ie, if the table consists of double values, how can i get the nth column into a double.

I feel like i have been doing it in a silly way, (iterating every row and every datacell until i get to that column :frowning: .)

I appreciate your help :slight_smile:

Hi @toblatp,

If you have the index of the column you want to access, e.g. by doing something like

final int colIdx = inData[0].getDataTableSpec().findColumnIndex("ColName")

you can iterate over the rows of the input table and get the cells directly:

for (DataRow row : inData[0]){
   DataCell cell =  row.getCell(colIdx);
}

best,
Gabriel

Thanks again Gabriel, appreciate your help :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.