I have a List. I want to get the index of the (first) user in the stream with a particular username. I don\'t want to actually require the Us
A solution without any external library
AtomicInteger i = new AtomicInteger(); // any mutable integer wrapper
int index = users.stream()
.peek(v -> i.incrementAndGet())
.anyMatch(user -> user.getName().equals(username)) ? // your predicate
i.get() - 1 : -1;
peek increment index i while predicate is false hence when predicate is true i is 1 more than matched predicate => i.get() -1