Friday 27 March 2020

TableSaw: Selections: Filter the information

Selections are used to filter the information in both columns and tables.

Example
Selection selection = intColumn.isLessThan(30);

Above statement gives a selection, that contains indexes of the elements that are < 30.

App.java
package com.sample.app;

import it.unimi.dsi.fastutil.ints.IntIterator;
import tech.tablesaw.api.IntColumn;
import tech.tablesaw.selection.Selection;

public class App {

 public static void main(String args[]) {
  int[] numbers = { 2, 4, 103, 24, 53, 23, 12, 11, 56, 6 };

  IntColumn intColumn = IntColumn.create("My Numbers", numbers);

  Selection selection = intColumn.isLessThan(30);

  IntIterator iterator = selection.iterator();

  System.out.println("Index Element");
  while (iterator.hasNext()) {
   int index = iterator.nextInt();

   System.out.println(index + "\t" + intColumn.get(index));
  }
 }
}

Output
Index Element
0 2
1 4
3 24
5 23
6 12
7 11
9 6


Previous                                                    Next                                                    Home

No comments:

Post a Comment