Table table;
void setup() {
table = new Table();
table.addColumn("name", Table.STRING);
table.addColumn("age", Table.INT);
table.addColumn("height", Table.FLOAT);
table.addColumn("weight", Table.FLOAT);
TableRow[] Row = new TableRow[2];
Row[0] = table.addRow();
Row[0].setString("name", "Jermaine");
Row[0].setInt("age", 15);
Row[0].setFloat("height", 188);
Row[0].setFloat("weight", 20);
Row[1] = table.addRow();
Row[1].setString("name", "Chanon");
Row[1].setInt("age", 32);
Row[1].setFloat("height", 188);
Row[1].setFloat("weight", 120);
saveTable(table, "data/new.csv");
}
-------------------------------------------------------------
table = loadTable("data/new.csv", "header");
println(table.getRowCount() + " total rows in table");
for (TableRow row : table.rows()) {
float h = row.getFloat("height");
int a = row.getInt("age");
float w = row.getFloat("weight");
String name = row.getString("name");
println(name + " has a " + w + " kg and " + h + " cm and age of " + a);
}
}
No comments:
Post a Comment