Sometimes it would be convenient to do something (for example, printing) with each flow element between the stages of flow processing, for example. for debugging.
A simple example might look like this, unfortunately this does not work, since forEach consumes a stream:
List<String> list = new ArrayList<>(); list.add("one"); list.add("two"); list.add("three"); list.add("four"); List<String> filteredList = list.stream() .filter(s -> s.startsWith("t")) .forEach(System.out::println) .collect(Collectors.toList());
How can this be achieved?
source share