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?
Advertisement
Answer
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());