Skip to main content
Version: Java (Groovy)

Create a table with emptyTable

This guide will show you how to create an empty, in-memory user table. Empty tables contain rows but no columns. Selection methods can be used to add columns to empty tables.

Here, we will use the emptyTable method to create a table with five rows and zero columns. The sole argument is the number of rows to be included in the new table. Copy and run the following code in your console:

empty = emptyTable(5)

Groovy users need to import the TableTools package.

Now you can update your table to contain data.

The examples below use the update method to create a new column. The column type will reflect the data specified in the selection method's argument; in other words, if your data is a set of integers, an int column is created automatically.

In the following query, we add a new column (X), which contains the same integer value (5) in each row.

result = empty.update("X = 5")

In the following query, we create a new column (X), which contains the values from array a. The special variable i is the row index.

a = [1, 2, 3, 4, 10] as int[]

result2 = empty.update("X = a[i]")