Thursday 26 March 2020

TableSaw: Working with Columns

Column represents one-dimensional collection of data. ‘tech.tablesaw.columns.Column’ represents a tablesaw column. Columns can exists on their own (or) can be part of a table.

All the elements in a columns must be of same type.

For example, below statements create an Int Column from an integer array.
int[] primes = { 2, 3, 5, 7, 11, 13, 17, 19 };
IntColumn intColumn = IntColumn.create("My Primes", primes);

App.java
package com.sample.app;

import tech.tablesaw.api.IntColumn;

public class App {

 public static void main(String args[]) {
  int[] primes = { 2, 3, 5, 7, 11, 13, 17, 19 };

  IntColumn intColumn = IntColumn.create("My Primes", primes);
  
  System.out.println(intColumn.print());
 }
}

Output
Column: My Primes
2
3
5
7
11
13
17
19

How to access the elements of a column?
Use get() method to access the elements of a column.

How to get number of elements of a column?
size() method returns total number of elements in a column.

App.java
package com.sample.app;

import tech.tablesaw.api.IntColumn;

public class App {

 public static void main(String args[]) {
  int[] primes = { 2, 3, 5, 7, 11, 13, 17, 19 };

  IntColumn intColumn = IntColumn.create("My Primes", primes);

  System.out.println("Elements in intColumn are");
  for (int i = 0; i < intColumn.size(); i++) {
   System.out.println(intColumn.get(i));
  }
 }
}

Output
Elements in intColumn are
2
3
5
7
11
13
17
19



Previous                                                    Next                                                    Home

No comments:

Post a Comment