I have a CSV file and the first line contains the headers. So I thought it would be perfect to use Java 8 streams.
try (Stream<String> stream = Files.lines(csv_file) ){
stream.skip(1).forEach( line -> handleLine(line) );
} catch ( IOException ioe ){
handleError(ioe);
}
Is it possible to take the first element, analyze it and then call the forEach method? Something like
stream
.forFirst( line -> handleFirst(line) )
.skip(1)
.forEach( line -> handleLine(line) );
ADDITIONALLY: My CSV file contains around 1k lines and I can handle each line parallel to speed it up. Except the first line. I need the first line to initiallize other objects in my project :/ So maybe it is fast to open a BufferedReader, read the first line, close the BufferedReader and than use parallel streams?