I have a Stream<ArrayList<Object>> and I want to "extract" the ArrayList from it and assign it to a variable. How do I do that?
My resulting variable needs to be of type ArrayList<Object> so I can iterate over it and do stuff.
I have a Stream<ArrayList<Object>> and I want to "extract" the ArrayList from it and assign it to a variable. How do I do that?
My resulting variable needs to be of type ArrayList<Object> so I can iterate over it and do stuff.
 
    
    If you want to get one ArrayList then use
ArrayList<Object> result = strm.flatMap(ArrayList::stream)
        .collect(Collectors.toCollection(ArrayList::new));
 
    
    Stream.flatMap method lets you replace each value of a stream with
another stream and then concatenates all the generated streams into a single stream.
List<Object> objectList = new ArrayList<>();
        List<Object> collect = Stream.of(objectList)
                .flatMap(m -> m.stream())
                .collect(Collectors.toList());
