Stream Manipulation (Java 8)

1

Hi, I have a String Stream with many lines of a txt, I need to do a split to break the lines in the pipes, but the return as you know is a String vector, to know if this is possible:

Stream<String> linhas=Files.lines(caminho,StandardCharsets.ISO_8859_1);
/**Alguma coisa aqui...**/
Stream<String[]> linhasSemPipe;//Resultado

Manipulating only Streams, without converting to another type.

Thanks in advance for your attention.

    
asked by anonymous 02.03.2017 / 15:51

2 answers

1

You can use the map method.

Stream<String[]> linhasSemPipe =  Files.lines(caminho,StandardCharsets.ISO_8859_1)
                                       .map(linha -> linha.split("\|"));
    
02.03.2017 / 16:33
1

You can try something like this by returning Stream :

Stream<String> linesByPipe = 
   Files.lines(caminho)
        .map(line -> line.split("\|")) // Quebra por '|'

Or so, returning a List :

List<String> linesByPipe = 
   Files.lines(caminho)
        .map(line -> line.split("\|")) // Quebra por '|' 
        .collect(Collectors.toList());
    
02.03.2017 / 17:15