Sunday 5 April 2020

TableSaw: Get all the columns of a table

'table.columns()' method returns all the columns of a table.

Example
List<Column<?>> columns = table.columns();

for(Column column : columns) {
 System.out.println(column.print());
}

App.java
package com.sample.app;

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

import java.util.*;

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));

  List<Column<?>> columns = table.columns();
  
  for(Column column : columns) {
   System.out.println(column.print());
  }
  
 }
}

Output

Column: Employee Ids
1
2
3
4
5
6
7
8
9

Column: FirstName
Hari
Ram
Chamu
Sowmya
Harini
Lahari
Rama
Lakshman
Sandya



Previous                                                    Next                                                    Home

No comments:

Post a Comment