Suppose I have a string/object having some data in pipe separated format as below
***Input:***
TIMESTAMP|COUNTRYCODE|RESPONSETIME|FLAG
1544190995|US|500|Y
1723922044|GB|370|N
1711557214|US|750|Y
I want to read this string/object and filter data based on particular columns names (assume for eg. TIMESTAMP and FLAG). And return/display the output as shown below-
***Output:***
TIMESTAMP|FLAG
1544190995|Y
1723922044|N
1711557214|Y
I tried using below code:
First i have required header names stored an array:
headerArray[] = {TIMESTAMP, FLAG}By comparing
headerArray[]with first row of input, I got the index of specified column header in input:headerIndex[] = {0, 3}Then tried using below code to filter and get the specified columns and values:
return br.lines() .skip(1) // skip headers .map(s -> s.split("|")) .filter(a -> a[0] && a[3]) .collect(Collectors.toList());
Note: I have over a million lines of pipe separated values. And I want to return all filtered out column values in a single object. I suppose that not possible by returning value as list.
.filter(a -> a[0] && a[3])surely doesn’t even compile.