Class Name

Table

Description

Table objects store data with multiple rows and columns, much like in a traditional spreadsheet. Tables can be generated from scratch, dynamically, or using data from an existing file. Tables can also be output and saved to disk, as in the example above.

Additional Table methods are documented in the Processing Table Javadoc.

Examples

  • Table table;
    
    void setup() {
    
      table = new Table();
      
      table.addColumn("id");
      table.addColumn("species");
      table.addColumn("name");
      
      TableRow newRow = table.addRow();
      newRow.setInt("id", table.lastRowIndex());
      newRow.setString("species", "Panthera leo");
      newRow.setString("name", "Lion");
      
      saveTable(table, "data/new.csv");
    }
    
    // Sketch saves the following to a file called "new.csv":
    // id,species,name
    // 0,Panthera leo,Lion
    

Constructors

  • Table()
  • Table(rows)

Methods

  • addColumn()Adds a new column to a table
  • removeColumn()Removes a column from a table
  • getColumnCount()Returns the total number of columns in a table
  • getRowCount()Returns the total number of rows in a Table
  • clearRows()Removes all rows from a Table
  • addRow()Adds a new row of data to a Table object
  • removeRow()Removes a row from a Table object
  • getRow()Returns a reference to the specified TableRow
  • rows()Gets all rows from the table
  • getInt()Retrieves an integer value from the Table's specified row and column
  • setInt()Stores an integer value in the Table's specified row and column
  • getFloat()Retrieves a float value from the Table's specified row and column
  • setFloat()Stores a float value in the Table's specified row and column
  • getString()Retrieves a String value from the Table's specified row and column
  • setString()Stores a String value in the Table's specified row and column
  • getStringColumn()Retrieves all values in the specified column
  • findRow()Finds a row that contains the given value
  • findRows()Finds multiple rows that contain the given value
  • matchRow()Finds a row that matches the given expression
  • matchRows()Finds multiple rows that match the given expression
  • matchRowIterator()Finds multiple rows that match the given expression
  • removeTokens()Removes characters from the table
  • trim()Trims whitespace from values
  • sort()Orders a table based on the values in a column