It appears that the full example can be solved without the use of any kind of Pair structure. The key is to filter on the column indexes, with the predicate checking the entire column, instead of mapping the column indexes to the number of false
entries in that column.
The code that does this is here:
System.out.println(
IntStream.range(0, acyclic_graph.length)
.filter(i -> IntStream.range(0, acyclic_graph.length)
.noneMatch(j -> acyclic_graph[j][i]))
.boxed()
.collect(toList()));
This results in output of [0, 2, 4]
which is I think the correct result requested by the OP.
Also note the boxed()
operation that boxes the int
values into Integer
objects. This enables one to use the pre-existing toList()
collector instead having to write out collector functions that do the boxing themselves.