Thursday 2 April 2020

TableSaw: Get number of rows and columns in a table

‘table.rowCount()’ returns number of rows in a table.
‘table.columnCount()’ returns number of columns in a table.

App.java
package com.sample.app;

import tech.tablesaw.api.IntColumn;
import tech.tablesaw.api.StringColumn;
import tech.tablesaw.api.Table;

public class App {

 public static void main(String args[]) {
  int[] empIds = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  String[] firstNames = { "Hari", "Ram", "Chamu", "Sowmya", "Harini", "Lahari", "Rama", "Lakshman", "Sandya" };

  Table table = Table.create().addColumns(IntColumn.create("Employee Ids", empIds))
    .addColumns(StringColumn.create("FirstName", firstNames));

  table.setName("Employee Information");

  System.out.println("Row Count : " + table.rowCount());
  System.out.println("Column Count : " + table.columnCount());
 }
}

Output
Row Count : 9
Column Count : 2

Previous                                                    Next                                                    Home

No comments:

Post a Comment