Skip to content
Advertisement

Get every nth element of nested lists using Java Streams

Here’s a function that will take a nested ArrayList allLists, an index nth, and return the nth element of every sublist.

E.g. for allLists = {{1,2,3}, {4,5,6}, {7,8,9}}, nth = 1, the function will return {2,5,8}

JavaScript

I’ve managed to get a version working where I can print it out:

JavaScript

How to gather the results into an array?

Advertisement

Answer

Solved:

JavaScript
Advertisement