I have this list (List):
[\"a\", \"b\", null, \"c\", null, \"d\", \"e\"]
And I\'d like something like this:
Group by different token whenever you find a null (or separator). I used here a different integer (used atomic just as holder)
Then remap the generated map to transform it into a list of lists.
AtomicInteger i = new AtomicInteger();
List> x = Stream.of("A", "B", null, "C", "D", "E", null, "H", "K")
.collect(Collectors.groupingBy(s -> s == null ? i.incrementAndGet() : i.get()))
.entrySet().stream().map(e -> e.getValue().stream().filter(v -> v != null).collect(Collectors.toList()))
.collect(Collectors.toList());
System.out.println(x);