There is a simply:
public class Task{
private String name;
private List<Task> subtasks;
}
and a list of Task objects. How is it possible to get list of every Task as subtask by using stream().
I tried this one:
List<Task> subtasks = myTask.stream().map(x -> x.getSubtasks()).collect(Collectors.toList());
but it returns List<List<Task>>. What is the best way to join array from map() to existing result?
flatMap(x -> x.getSubtasks().stream())instead of yourmap()TaskinsideTask. If the rabbit hole doesn't go deeper, that duplicate should do.