Sunday, 5 April 2020

TableSaw: Print all the rows in console

'table.printAll()' method returns a string representation of 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));

  System.out.println(table.printAll());
 }
}

Output

Employee Ids  |  FirstName  |
------------------------------
            1  |       Hari  |
            2  |        Ram  |
            3  |      Chamu  |
            4  |     Sowmya  |
            5  |     Harini  |
            6  |     Lahari  |
            7  |       Rama  |
            8  |   Lakshman  |
            9  |     Sandya  |





Previous                                                    Next                                                    Home

No comments:

Post a Comment