How to convert 2D list to 1D list with Streams?

Viewed 4257

I've tried this code (list is ArrayList<List<Integer>>):

list.stream().flatMap(Stream::of).collect(Collectors.toList());

but it doesn't do anything; the list is still a 2D list. How can I convert this 2D list to a 1D list?

3 Answers
Related