Reputation: 15
var validPushes: MutableList<Push> = IntStream.range(0, pushQuantity).mapToObj { inx -> readPush()}
.filter { push -> processor.validatePush(push, state)}
.collect(Collectors.toList());
How to write this java code without java.util.stream library? I could not find an analog to mapToObj. map does not fit, because I need to cast it to Obj. Collectros replaced by asSequense
Upvotes: 0
Views: 95
Reputation: 28036
You can use a range to do the counting. You can convert the range to a sequence in order to keep the lazy nature of your Stream
.
val validPushes = (0 until pushQuantity)
.asSequence()
.map { readPush() }
.filter { processor.validatePush(it, state) }
.toMutableList()
Upvotes: 1