I have a file. I get Stream using Files.lines. The file is big. I need to go through it in a loop and form several arrays. During the passage through the file, each generated array must be passed to the method that will process it. I know that there are PartitioningBy and GroupingBy methods, but I do not know how to apply them to my task. I'm trying to do this:
@Test
public void myTest() {
Stream<String> lines = Stream.of(
"some row from my file 1",
"some row from my file 2",
"some row from my file 3",
"some row from my file 4",
"some row from my file 5",
"some row from my file n",
"some row from my file 750000"
);
lines.parallel()
.unordered()
.collect(Collectors.partitioningBy(s -> s == 3).supplier(it -> {
myParser(it);
}));
}
public void myParser(List<String> myList){
//this piece of code should give the length of the transmitted array
System.out.println(myList.size());
}
In the myParser method, I want to get arrays of 3 elements and process them