I’m working on an app that deals with animals by category.
public class Animal { private long id; private color String ; ... }
I have several arrayList with animal objects.
I manage to gather all my arrayList in another arrayList
So i have:
ArrayList <ArrayList<Animal>>
my goal is to put all arrayList in a single arrayList
In summary:
Before : ArrayList <ArrayList<Animal>> After: ArrayList<Animal> with a same list of Animals
I manage to do it in procedural programming easily but I don’t know how to do it in functional programming with Stream from Java 8
>Solution :
You can solve with Flatmap with stream, Collect
ArrayList<ArrayList<Animal>> SingleListofAnimal = new ArrayList<ArrayList<Animal>>();
SingleListofAnimal = List.stream() .flatMap(List::stream) .collect(Collectors.toList());
Let me know if it works for you