How can I override next() for jagged array java?

This might be a wrong answer to your question. I’ll remove it in that case, but maybe you can use it for what you want to achieve:

int[][] it = {{1,2}, {3,4,5}};

OfInt iterator = Arrays.stream(it).flatMapToInt(x -> IntStream.of(x)).iterator();
iterator.forEachRemaining((IntConsumer) System.out::print);

Stream the jagged array, flatmap it into one single IntStream and then do what you want with it. In this example I fetched the iterator but you might only want:

Arrays.stream(it).flatMapToInt(x -> IntStream.of(x)).forEach((IntConsumer) System.out::print); 

In forEach you can do what you need, or use some other method of IntStream

Leave a Comment