The filter is filtering the stream down to only elements that match the condition number == 7
(i.e. only a single element, which happens to be the Integer 7), then next()
returns the first (and only) element. Remember, in order to get the first element from an Iterator
, you need to call next()
once.
If you definitely want the first element after the 7 in this ordered list, you can change your filter to number -> number > 7
.