I have following code:
new Random().ints()
.map(i -> i / 2)
.limit(100)
.toArray()
...and it works as expected.
But this doesn't work:
new Random().ints()
.sorted()
.map(i -> i / 2)
.limit(100)
.toArray()
It throws:
Exception in thread "main" java.lang.IllegalArgumentException: Stream size exceeds max array size
Shouldn't limit shortcircuit the stream and help in restricting it to 100 elements?