Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

TableSaw: Select specific column from a table

‘table.select’ method return new Table with specific columns.

Example
Table resultedTable = table.select("FirstName", "LastName");

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 };
String[] firstNames = { "Hari", "Ram", "Sowmya", "Chamu", "Swethank", "Chamu" };
String[] lastNames = { "Krishna", "Gurram", "Maj", "Maj", "Baji", "Gurram" };

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

Table resultedTable = table.select("FirstName", "LastName");

System.out.println(table.print());
System.out.println("\n" + resultedTable.print());

}
}

Output
Employee Id  |  FirstName  |  LastName  |
------------------------------------------
           1  |       Hari  |   Krishna  |
           2  |        Ram  |    Gurram  |
           3  |     Sowmya  |       Maj  |
           4  |      Chamu  |       Maj  |
           5  |   Swethank  |      Baji  |
           6  |      Chamu  |    Gurram  |

 FirstName  |  LastName  |
--------------------------
      Hari  |   Krishna  |
       Ram  |    Gurram  |
    Sowmya  |       Maj  |
     Chamu  |       Maj  |
  Swethank  |      Baji  |
     Chamu  |    Gurram  |




Previous                                                    Next                                                    Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

TableSaw: Select specific column from a table

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×