I have a Seq and need to use it to select columns in Java
I know about the function .select(String col, Seq<String> cols) but I don't have the first column name.
If you want to select using a Seq<String> you can split the Seq extracting the first element separately:
Seq<String> columns = /* ... */;
Dataframe<Row> newDf = df.select(
columns.apply(0), // first element
columns.slice(1, columns.size()) // from the second to the end
);
maybe check the length of columns first, to avoid IndexOutOfBoundsException
select function takes in input (String,Seq<String>) but slice returns Scala iterable, so had to do toSeq() to it. columns.slice(...).toSeq()
df.columnsreturns an array with the names of the columns..select(Seq<String> cols)method