Saturday, 11 April 2020

TableSaw: Print table row wise

Using ‘Row’, you can traverse the table row wise.

Example
Row row = new Row(table);

while (row.hasNext()) {
         System.out.println(row.next() + "\n");
}

App.java
package com.sample.app;

import tech.tablesaw.api.IntColumn;
import tech.tablesaw.api.Row;
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 };
  String[] firstNames = { "Hari", "Ram", "Sowmya", "Chamu", "Hareesh" };
  String[] lastNames = { "Krishna", "Gurram", "Maj", "Dev", "Baji" };

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

  Row row = new Row(table);

  while (row.hasNext()) {
   System.out.println(row.next() + "\n");
  }

 }
}

Output

Employee Ids  |  FirstName  |  LastName  |
-------------------------------------------
            1  |       Hari  |   Krishna  |

 Employee Ids  |  FirstName  |  LastName  |
-------------------------------------------
            2  |        Ram  |    Gurram  |

 Employee Ids  |  FirstName  |  LastName  |
-------------------------------------------
            3  |     Sowmya  |       Maj  |

 Employee Ids  |  FirstName  |  LastName  |
-------------------------------------------
            4  |      Chamu  |       Dev  |

 Employee Ids  |  FirstName  |  LastName  |
-------------------------------------------
            5  |    Hareesh  |      Baji  |



Previous                                                    Next                                                    Home

No comments:

Post a Comment