Tuesday 7 April 2020

TableSaw: Column names are case insensitive

Column names are case insensitive in TableSaw.

For example, You get the same column if you ask for any of these.

Column<?> column1 = table.column("FirstName");
Column<?> column2 = table.column("firstName");
Column<?> column3 = table.column("FIRSTNAME");

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;

public class App {

      public static void main(String args[]) {
            int[] empIds = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            String[] firstNames = { "Hari", "Ram", "Sowmya", "Chamu", "Harini", "Lahari", "Rama", "Lakshman", "Sandya" };
            String[] lastNames = { "Krishna", "Gurram", "Maj", "Dev", "Gurram", "Ram", "Sen", "Grandi", "Neelam" };

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

            System.out.println(table.print());
            
            Column<?> column1 = table.column("FirstName");
            Column<?> column2 = table.column("firstName");
            Column<?> column3 = table.column("FIRSTNAME");
            
            System.out.println(column1.print());
            System.out.println(column2.print());
            System.out.println(column3.print());

      }
}


Output

Employee Ids  |  FirstName  |  LastName  |
-------------------------------------------
            1  |       Hari  |   Krishna  |
            2  |        Ram  |    Gurram  |
            3  |     Sowmya  |       Maj  |
            4  |      Chamu  |       Dev  |
            5  |     Harini  |    Gurram  |
            6  |     Lahari  |       Ram  |
            7  |       Rama  |       Sen  |
            8  |   Lakshman  |    Grandi  |
            9  |     Sandya  |    Neelam  |
Column: FirstName
Hari
Ram
Sowmya
Chamu
Harini
Lahari
Rama
Lakshman
Sandya

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

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



Previous                                                    Next                                                    Home

No comments:

Post a Comment