I know how to find the first element of a list by predicate: Find first element by predicate
Is there an easy way to get the index of that element?
If I understood correctly, that's the classic case where you need IntStream
; but that would only apply for a List obviously.
IntStream.range(0, yourList.size())
.filter(i -> yourList.get(i)... your filter condition)
.collect(Collectors.toList());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With